[英]How can I receive all document objects from a collection in cloud-firestore?
When I try to receive a document from a subcollection I get an object with only the values from the document.当我尝试从子集合中接收文档时,我得到一个 object,其中仅包含文档中的值。
The response looks like this:响应如下所示:
{
id: mealDocumentId,
name: 'Burger',
imageUrl: 'imgUrl1',
price: 3, quantity: 1
}
Is there a way to receive the object from the entire document?有没有办法从整个文档中接收 object?
I was expecting the objects from the documents similar to this:我期待文档中的对象与此类似:
{
mealDocumentId1: {
name: 'Burger1',
imageUrl: 'imgUrl1',
price: 1,
quantity: 1,
},
mealDocumentId2: {
name: 'Burger2',
imageUrl: 'imgUrl2',
price: 2,
quantity: 2,
},
}
The Code I'm running:我正在运行的代码:
constructor(private db: AngularFirestore) { }
getAllMealDocuments() {
// this is the path to the subselection meals
const docRef = this.db.collection('tables').doc('documentId').collection('meals');
// try to get a document object and pass it.
return docRef.snapshotChanges().pipe(map(document => {
document.map(doc => {
return new Meal({
id: doc.payload.doc.id,
...(doc.payload.doc.data() as {})
});
});
}));
}
Is there another way to receive all the documents?是否有其他方式接收所有文件? Preferably like the expected formate?
最好喜欢预期的甲酸盐? Thanks!
谢谢!
It sounds like you're looking for the documentChanges
stream , which (unlike valueChanges
) includes the ID of each document in its output.听起来您正在寻找
documentChanges
stream ,它(与valueChanges
不同)在其 output 中包含每个文档的 ID。
I'd recommend checking out the AngularFire documentation on streaming collection data for the types of streams, and the differences between them.我建议查看关于流式收集数据的 AngularFire 文档,了解流的类型以及它们之间的区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.