简体   繁体   English

Angularfire更新嵌套数据

[英]Angularfire Update nested data

I am using angularfire and firebase firestore database to save image data in a database. 我正在使用angularfire和firebase firestore数据库将图像数据保存在数据库中。 The saving works 100%. 节省100%。

My data is nested like this : 我的数据像这样嵌套:

Images Collection 图片集

  • galleryId galleryId
    • imageId 图像标识
      • name 名称
      • path 路径
    • imageId 图像标识
      • name 名称
      • path 路径
  • galleryId galleryId
    • imageId 图像标识
      • name 名称
      • path 路径

Sometimes I need to update a specific image object in the database, however, when I try do update an image object / doc I get the following error: 有时我需要更新数据库中的特定图像对象,但是,当我尝试更新图像对象/文档时,出现以下错误:

Invalid document reference. Document references must have an even number of segments, but images/yuEXbpYWqE4AUfmRCxIu/JvLzEANRFlupuUxYXNii has 3

This is the code I user : 这是我使用的代码:

this.afs.doc('images'+'/'+galleryId+'/'+imageId+'/').update({"name": upload.name,"path": upload.url});

I have also tried : 我也尝试过:

this.afs.doc('images').collection(galleryId).doc(imageId).update({"name": upload.name,"path": upload.url});

and I have also tried : 而且我也尝试过:

 this.afs.collection('images'+'/'+galleryId).doc(imageId).update({"name": upload.name,"path": upload.url});

and then I get a similar error, just referencing the collection this time : 然后出现类似的错误,这次只是引用集合:

 Invalid collection reference. Collection references must have an odd number of segments, but images/AHcWODRgsespIExQnJae has 2

When I try to update other collections in my database it works fine, however, they are only nested 2 levels. 当我尝试更新数据库中的其他集合时,它可以正常工作,但是它们仅嵌套2级。 It seems that when you have nested 3 levels there are issue. 看来,当您嵌套3个级别时,就会出现问题。

Please help 请帮忙

You cannot have a document nested directly under another document. 您不能将文档直接嵌套在另一个文档下。 You have to structure your nests accordingly: collection - document - collection - document - etc. Firestore paths always start with a collection. 您必须相应地构造嵌套:集合-文档-集合-文档-等。Firestore路径始终以集合开头。

this.afs.doc('images/'+galleryId + '/images/' + imageId).update({"name": upload.name,"path": upload.url});

I would suggest reading the firestore documentation as this is a fundamental aspect of firestore: https://firebase.google.com/docs/firestore/ 我建议您阅读Firestore文档,因为这是Firestore的基本方面: https : //firebase.google.com/docs/firestore/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在(angularfire2 / Ionic)中更新Firebase数据的嵌套对象,并且我也想使用给定值而不是键进行更新 - How to update nested object of firebase data in (angularfire2 / Ionic), and also i want to update with given value not with key Firebase / Angularfire2:firebase中的嵌套数据节点 - Firebase / Angularfire2: nested data nodes in firebase Angularfire:从控制器中的$ firebaseObject获取嵌套数据 - Angularfire: Getting nested data from a $firebaseObject in controller 专家想要AngularFire2 firestore嵌套集合获取数据吗? - Expert wanted AngularFire2 firestore nested collection get data? 从angularfire2 5.0.0-rc.2中检索嵌套数据列表 - Retrieve nested data list from angularfire2 5.0.0-rc.2 如何使用Firebase和angularfire立即更新数据列表中的项目? - How to instantly update an item within a list of data with firebase and angularfire? Angularfire2-是否可以通过查询更新Firebase列表的数据? - Angularfire2 - Is possible to update the data of firebase list by query? Firebase 更新数据,但几秒钟后将其更改回原始“angularFire” - Firebase update data , but change it back to original after few seconds "angularFire" angularFire 3种方式的数据绑定不会更新功能 - angularFire 3 way data binding won't update an function AngularFire Firestore嵌套查询 - AngularFire Firestore Nested Query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM