[英]Firestore update multiple records
我有一組文檔希望在此之后更新:
https://firebase.google.com/docs/firestore/manage-data/add-data
我希望將每個文檔中的一個字段增加 2 的值。
const collection = db.collection('groups').where('age', '> 20', right).get()
.then(response => {
response.docs.forEach((doc) => {
let updateGroup = doc.update(
{
days: doc.days + 2;
}
);
})
})
當我運行上面的代碼時,我收到以下錯誤:TypeError: doc.update is not a function
您的doc
變量不是DocumentReference 。 這是一個DocumentSnapshot 。 您可以從 API 文檔中看到它沒有update()
方法。 如果您想要快照中的 DocumentReference,請使用其ref
屬性。
doc.ref.update(...)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.