【问题标题】:Firestore update multiple recordsFirestore 更新多条记录
【发布时间】:2020-06-17 04:14:28
【问题描述】:

我有一组文档希望在此之后更新:

https://firebase.google.com/docs/firestore/manage-data/add-data

我希望将每个文档中的字段增加 2。

const collection = db.collection('groups').where('age', '> 20', right).get()
    .then(response => {
        response.docs.forEach((doc) => {
            let updateGroup = doc.update(
                {
                    days: doc.days + 2;
                }
            );
        })
    })

当我运行上面的代码时,我收到以下错误: TypeError: doc.update 不是函数

【问题讨论】:

    标签: javascript node.js google-cloud-firestore


    【解决方案1】:

    您的doc 变量不是DocumentReference。这是DocumentSnapshot。您可以从 API 文档中看到它没有 update() 方法。如果您想要快照中的 DocumentReference,请使用其 ref 属性。

    doc.ref.update(...)
    

    【讨论】:

      猜你喜欢
      • 2019-02-18
      • 2016-05-01
      • 2013-05-02
      • 2014-03-04
      • 2015-12-07
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多