如何在python中增加Firestore字段值?

ish*_*007 5 firebase google-cloud-functions google-cloud-firestore

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
Run Code Online (Sandbox Code Playgroud)

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

Lau*_*Mat 1

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

然后您可以使用Transforms,例如IncrementArrayRemove等。

示例代码:

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