gpt4 book ai didi

javascript - Firestore 更新集合中的所有文档

转载 作者:行者123 更新时间:2023-12-01 14:55:46 26 4
gpt4 key购买 nike

我有一个名为 users 的 firestore 集合,每个用户都有一个带有字段 score 的生成 id:

users 
0e8X3VFL56rHBxxgkYOW
score : 4
3SeDjrgAWMmh3ranh2u
score : 5

我使用 redux-firestore,我想将所有用户的分数重置为 0,比如
firestore.update({ collection: 'users' }, { score : 0 }

我无法做到这一点,因为更新方法需要一个文档 ID

你知道怎么做吗?

最佳答案

您可以获取集合中的所有文档,获取它们的 id 并使用这些 id 执行更新:

db.collection("cities").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
doc.ref.update({
capital: true
});
});
});

关于javascript - Firestore 更新集合中的所有文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51481192/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com