如何在python中增加Firestore字段值? [英] How to increment Firestore field value in python?

查看:34
本文介绍了如何在python中增加Firestore字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

shard_ref.update("count",firebase.firestore.FieldValue.increment(1));

我正在寻找在python中进行增量和更新的方法,我甚至不希望在python中使用预定义的值对其进行更新.该文档未指定任何python示例.我正在像这样使用 firebase_admin sdk,

I am looking for way to increment and update in python, I am not abe to even update it with a predefined value in python. the doc doesn't specify any python samples. I am using firebase_admin sdk like this,

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

了解更多检查文档 https://firebase.google.com/docs/firestore/solutions/counters

推荐答案

不幸的是(对我来说,这感觉不对),在代码库中添加对转换的支持意味着您必须使用

Unfortunately (to me it just doesn't feel right), adding support for transforms in your codebase means you have to use google-cloud-firestore next to firebase_admin.

然后您可以使用转换,例如 Increment code>, ArrayRemove

You can then use Transforms such as Increment, ArrayRemove, etc.

示例代码:

from google.cloud.firestore_v1 import Increment
# assuming shard_ref is a firestore document reference
shard_ref.update({'count': Increment(1)})

这篇关于如何在python中增加Firestore字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆