从Firebase的Firestore读取时无法写入值。说“更新不是功能”

时间:2019-09-16 23:26:43

标签: javascript firebase google-cloud-firestore

我试图读取数据库中的奖金池,而不是将该奖金池添加到用户余额中。这似乎很简单,但是在Firestore和Firebase中却很难。

def fill(a, ind, startval):
    res = np.zeros(len(a) + 1)
    res[0] = startval
    for i in range(len(a)):
        if i in ind:
            res[i + 1] = a[i] + 10
        else:
            res[i + 1] = res[i]
    print(res[1:])

在控制台中,我被告知更新不是功能。我也尝试过用

        const totalEach = db.collection('prizes').doc('prize2AM');

        totalEach.get().then((choice: any) => {
            let total = choice.data().amount

            let tempUser = db.collection('users', ref => ref.where('id', '==', 'seRCUOAYSbOm8QbG0JI3ssHCMsZ2'));

            tempUser.get().then(userGet => {
              let userBalance = choice.data().amount

              tempUser.update({
                balance: userBalance+=total
              });
            });

        });

并得到同样的结果,没有发生函数错误。

此外,我尝试在语句的各个位置添加ref。例如db.ref.collection,但这也给我一个错误。说该集合是未定义的,或者您无法读取未定义的更新。

不太确定这里发生了什么,以及我应该如何更新我的信息。有任何想法吗?

1 个答案:

答案 0 :(得分:1)

tempUserQuery对象。从链接的API文档中可以看到,Query没有名为update的方法。您只能更新DocumentReference对象引用的单个文档。您无法“批量更新”查询的整个结果-您将必须执行查询,迭代结果,找到每个DocumentSnapshot的DocumentReference(使用其ref属性)并调用update ()分别放在一个。