Angularfire 更新嵌套数据

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/