[英]Firestore expressjs: how to get document where specific field exists and update the document
所以我在 firebase 雲 function 中使用 expressjs 試圖獲取一個特定字段與我已經擁有的值相同的文檔,所以這是一段代碼:
const email =data.email (this is coming from stripe webhook )
const document = db
.collection('ConnectedAccounts')
.where(`email`, '==', email)
.get();
console.log('document', document.data());
獲得此文檔后,我想在其中存儲一個新字段,我嘗試了上面的代碼但失敗了,有人可以幫忙嗎?
當您執行查詢時,響應是一個可以包含任意數量文檔的QuerySnapshot
。 因此,您需要遍歷該快照中的文檔以獲取各個結果:
const email =data.email (this is coming from stripe webhook )
const querySnapshot = await db
.collection('ConnectedAccounts')
.where(`email`, '==', email)
.get();
querySnapshot.docs.forEach((docSnapshot) => {
docSnapshot.ref.update({ ... your update here ...});
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.