【问题标题】:Is there a way to change a value in all documents on firestore? [duplicate]有没有办法更改 Firestore 上所有文档中的值? [复制]
【发布时间】:2019-10-14 05:25:57
【问题描述】:

我是使用 react-native 和 firebase 创建移动应用的初学者。 我有一个值存储在许多文档中,我想更新所有文档中的值

我尝试使用 .where() 子句,但出现错误

firebase.firestore().collection('myCollection').where('myValue','==','oldValue').update({myValue:newValue});

我预计数据会改变,但我收到了这个警告:

Possible Unhandled Promise Rejection (id: 0):
TypeError: _reactNativeFirebase.default.firestore(...).collection(...).where(...).update is not a function

请原谅我的英语不好

【问题讨论】:

    标签: javascript firebase react-native google-cloud-firestore react-native-firebase


    【解决方案1】:

    Firestore 不提供根据文档的当前值批量更新文档的方法。没有类似 SQL 的“update where”类型的语法。您必须首先查询并阅读所有要更改的文档,然后使用新值更新它们。

    【讨论】:

    • 所以如果我想更新所有文件。我应该先获取他们的 id,然后一个一个地更新它们
    • 是的,你需要这样做。
    猜你喜欢
    • 2020-02-27
    • 2019-12-20
    • 2020-01-22
    • 1970-01-01
    • 2013-07-05
    • 2017-09-28
    • 2010-10-07
    • 2020-11-02
    • 2010-09-14
    相关资源
    最近更新 更多