簡體   English   中英

更新 Firestore 中的所有文檔

[英]Update all documents in Firestore

我對我的文檔進行了更改,一個字符串字段現在是一個數組,名稱也更改了。 所以它來自:

phoneNumber: "+34616161616"

到:

phone: {
    phoneNumber: "616161616",
    phoneCode: "+34",
    isoCode: "ES"
}

在我的應用程序中進行重構后,我也支持舊版本,但我意識到我需要做很多更改。

我可以更新 Firestore 中的所有文檔嗎? Firebase 內部有什么方法可以立即更新它嗎?

結構是:

1- 用戶(收藏)--> 用戶 ID --> 投資組合(收藏)--> 投資組合 ID --> 租金(收藏)--> 收藏 ID --> 電話

2- 用戶(集合)--> userId --> 聯系人(集合)--> contactId --> 電話

functions.firestore.document('/accounts/{accountId}/resources/{resourceId}')

.onUpdate((change, context) => { const resource = context.params.resourceId;

return admin.firestore().collection('/accounts/'+account+'/tasks')
  .where('resourceId', '=', resource).get().then(snapshot => {
    const promises = [];
    snapshot.forEach(doc => {
      promises.push(doc.ref.update({
        fieldA: 'valueA',
        fieldB: 'valueB'
      }));
    });
    return Promise.all(promises)
})
.catch(error => {
  console.log(error);
  return null;
});

}); 這應該可以更新您的文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM