Javascript 是否可以通过云函数一次调用Firestore的多个更新查询?

Javascript 是否可以通过云函数一次调用Firestore的多个更新查询?,javascript,firebase,google-cloud-firestore,google-cloud-functions,Javascript,Firebase,Google Cloud Firestore,Google Cloud Functions,我正试图通过一个循环更新Firestore中的几个文档。它还创建了许多更新查询的实例,因此当我试图在Android、iOS和web客户端上的移动应用程序的客户端上聆听其更改时,这是一个混乱的解决方案 for (var item in ListOfData) { documentReference.update({ SupportedCity: item }) .then(function() { console.log("Document

我正试图通过一个循环更新Firestore中的几个文档。它还创建了许多更新查询的实例,因此当我试图在Android、iOS和web客户端上的移动应用程序的客户端上聆听其更改时,这是一个混乱的解决方案

for (var item in ListOfData) {
    documentReference.update({
        SupportedCity: item
    })
    .then(function() {
        console.log("Document successfully updated!");
    })
    .catch(function(error) {
        // The document probably doesn't exist.
        console.error("Error updating document: ", error);
    });
}

提前感谢您可以使用batch.firestore()。因此,不调用update,而是将其添加到批处理中

var batch = firestore.batch();
for (var item in ListOfData) {
 var reference = firestore.collection("[Collection_Path]").doc("Document_Path");
 batch.update/*set*/(reference , {
  SupportedCity: item
 });
}
batch.commit().then(function () {
 console.log("Document Updated");
});

我注意到你没有按照update()返回的承诺做任何事情。如果您在云中运行此功能,那么无论您使用何种方法更新数据,您肯定需要正确处理这些承诺。