[英]How do I retrieve the data of ALL of the users in my nested Firestore database using Ionic4/Angular
I am trying to retrieve the data of all my users in a nested Firestore database using angular. 我正在尝试使用angular在嵌套的Firestore数据库中检索所有用户的数据。 The data base looks like this users (id) -> posts(id) - { description: this is an image, image: imageURL} .
数据库看起来像这样的用户(id)-> posts(id)-{说明:这是一张图片,图片:imageURL}。
I am using a firebase function in this ionic app, and I can successfully get the data of a single user id using this code in the index.ts file. 我在此离子应用程序中使用了Firebase函数,并且可以使用index.ts文件中的此代码成功获取单个用户ID的数据。
const docs = await
admin.firestore().collection('people').doc('R7iR7csLaDZuhUvZJWiFCcaLt903').collection('tasks').limit(5).get() admin.firestore()。collection('people')。doc('R7iR7csLaDZuhUvZJWiFCcaLt903')。collection('tasks')。limit(5).get()
return docs.docs.map(doc => {
return {
postID: doc.id,
...doc.data()
}
})
})
However this only gets the data of a single file path in the database structure, and I want to retrieve the data of all the docs ID and not just one id. 但是,这仅获取数据库结构中单个文件路径的数据,我想检索所有文档ID的数据,而不仅仅是一个ID。
the home.ts file looks like this home.ts文件如下所示
constructor(private aff: AngularFireFunctions) {}
ngOnInit() {
const getFeed = this.aff.httpsCallable('getFeed')
this.posts = getFeed({}).subscribe(data=> {
console.log(data)
// this.posts = data
})
}
You most likely will want to normalize your database so you're not making calls into nested collections, if you really want to get all of the posts for all users. 如果您确实想获取所有用户的所有帖子,则您很可能希望规范化数据库,以免对嵌套集合进行调用。 To download an entire collection, it would be something like this:
要下载整个收藏集,将类似于以下内容:
const docs = await admin.firestore().collection('people').get()
Simply ping the collection
and not a document
只是ping
collection
而不是document
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.