【问题标题】:How to increment Firestore field value in python?如何在 python 中增加 Firestore 字段值?
【发布时间】:2023-03-11 12:32:02
【问题描述】:

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

【问题讨论】:

标签: firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

不幸的是(对我来说只是感觉不对),在代码库中添加对转换的支持意味着您必须在 firebase_admin 旁边使用 google-cloud-firestore

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

示例代码:

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

【讨论】:

    猜你喜欢
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 2018-11-18
    • 2019-10-11
    • 2019-07-18
    • 2016-10-25
    • 1970-01-01
    相关资源
    最近更新 更多