簡體   English   中英

Angularfire更新嵌套數據

[英]Angularfire Update nested data

我正在使用angularfire和firebase firestore數據庫將圖像數據保存在數據庫中。 節省100%。

我的數據像這樣嵌套:

圖片集

  • galleryId
    • 圖像標識
      • 名稱
      • 路徑
    • 圖像標識
      • 名稱
      • 路徑
  • galleryId
    • 圖像標識
      • 名稱
      • 路徑

有時我需要更新數據庫中的特定圖像對象,但是,當我嘗試更新圖像對象/文檔時,出現以下錯誤:

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.

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