gpt4 book ai didi

python - 如何使用python使用firestore字段增量?

转载 作者:太空宇宙 更新时间:2023-11-03 20:51:12 24 4
gpt4 key购买 nike

我正在寻找一种在 Python 中增加和更新 firestore 字段的方法。
似乎最近在 google-cloud-firestore 1.2.0 中添加了增量功能。 issue-7533 !这在Python中如何实现呢?任何示例实现引用代码都会非常有帮助。

from google.cloud import firestore
......
upd_ref_path.update({u'test_col': firestore.FieldValue.increment(1)})

我收到以下错误消息错误:AttributeError:模块“google.cloud.firestore”没有属性“FieldValue”

更新 -

此功能需要从 firestore 模块中使用附魔才能使用。问题 - issue-8173 ! 为此而开放。

对于临时解决方案,使用如下:

from google.cloud.firestore_v1 import Increment
doc_ref.set({u'test_col': Increment(1)}, merge=True)

最佳答案

检查documentation 。您应该能够像这样使用它:

from google.cloud import firestore
......
upd_ref_path.update({u'test_col': firestore.transforms.Increment(1)})

希望有帮助

关于python - 如何使用python使用firestore字段增量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56305290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com