
[英]How to update nested object of firebase data in (angularfire2 / Ionic), and also i want to update with given value not with key
[英]Angularfire Update nested data
我正在使用angularfire和firebase firestore數據庫將圖像數據保存在數據庫中。 節省100%。
我的數據像這樣嵌套:
圖片集
有時我需要更新數據庫中的特定圖像對象,但是,當我嘗試更新圖像對象/文檔時,出現以下錯誤:
Invalid document reference. Document references must have an even number of segments, but images/yuEXbpYWqE4AUfmRCxIu/JvLzEANRFlupuUxYXNii has 3
這是我使用的代碼:
this.afs.doc('images'+'/'+galleryId+'/'+imageId+'/').update({"name": upload.name,"path": upload.url});
我也嘗試過:
this.afs.doc('images').collection(galleryId).doc(imageId).update({"name": upload.name,"path": upload.url});
而且我也嘗試過:
this.afs.collection('images'+'/'+galleryId).doc(imageId).update({"name": upload.name,"path": upload.url});
然后出現類似的錯誤,這次只是引用集合:
Invalid collection reference. Collection references must have an odd number of segments, but images/AHcWODRgsespIExQnJae has 2
當我嘗試更新數據庫中的其他集合時,它可以正常工作,但是它們僅嵌套2級。 看來,當您嵌套3個級別時,就會出現問題。
請幫忙
您不能將文檔直接嵌套在另一個文檔下。 您必須相應地構造嵌套:集合-文檔-集合-文檔-等。Firestore路徑始終以集合開頭。
this.afs.doc('images/'+galleryId + '/images/' + imageId).update({"name": upload.name,"path": upload.url});
我建議您閱讀Firestore文檔,因為這是Firestore的基本方面: https : //firebase.google.com/docs/firestore/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.