[英]how to update firestore subcollection field
我正在嘗試update
Firestore中的字段,但找不到正確的調用:
changeAlertState(senderId, receiverId, alertType, bool){
let type = alertType == 'toBe' ? 'toBeAlerted' : 'toAlert';
this.afs.firestore
.collection("books")
.doc(senderId + '/' + receiverId)
.update({
[type]: bool
})
.then(() => {
console.log("Contact " + receiverId + " alert successfully updated!");
});
}
我收到此錯誤:
FirebaseError:[code = invalid-argument]:無效的文檔參考。 文檔引用的段數必須是偶數,但是book / 33KlbrBypXMe888vpO7dXgDVrfY2 / hLh7Ao7IABZBukEpGFK1I8lq1rx1包含3個
您要將字段路徑的一部分傳遞給對doc()
的調用。 那是行不通的,因為您需要(僅)將文檔ID傳遞給doc
。 之后,您可以使用分隔路徑段,從而為要更新的字段構建字段路徑.
var value = {};
value[receiverId+"."+type] = bool;
this.afs.firestore
.collection("books")
.doc(senderId)
.update(value)
另請參見有關更新嵌套對象中字段的文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.