[英]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 图片集
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.