shard_ref.update("count", firebase.firestore.FieldValue.increment(1));
我正在寻找在 python 中增量和更新的方法,我什至无法使用 python 中的预定义值来更新它。该文档没有指定任何 python 示例。
我在用firebase_admin
像这样的sdk,
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
更多检查文档https://firebase.google.com/docs/firestore/solutions/counters https://firebase.google.com/docs/firestore/solutions/counters
不幸的是(对我来说,这感觉不对),在代码库中添加对转换的支持意味着您必须使用谷歌云 Firestore https://googleapis.dev/python/firestore/latest/index.html旁边firebase_admin
.
然后您可以使用变换 https://googleapis.dev/python/firestore/latest/transforms.html例如Increment
, ArrayRemove
, etc.
示例代码:
from google.cloud.firestore_v1 import Increment
# assuming shard_ref is a firestore document reference
shard_ref.update({'count': Increment(1)})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)