简体   繁体   English

如何使用Ionic4 / Angular在嵌套的Firestore数据库中检索所有用户的数据

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

相关问题 如何在我的 ionic4 应用程序中检索特定详细信息新闻 - How can i retrieve a specfic details news in my ionic4 app 如何使用带角度的 Ionic4 查找 IMEI 号码 - How to find IMEI number using Ionic4 with angular 如何使用Angular 2和AngularFire2中的接口检索三层嵌套数据并保持其类型安全 - How do I retrieve three levels of nested data and keep it type safe using interfaces in Angular 2 and AngularFire2 如何在ionic4中使用crypto js进行加密/解密? - How to do encryption/decyption using crypto js in ionic4? 当我使用 ng serve 运行时,如何在我的 Angular6 项目中使用 ionic4 组件 - How can i use ionic4 component in my Angular6 project, when i use ng serve to run 我如何通过字段名称查询firestore并使用angular在ionic 4列表中生成数据 - How can i query firestore by field name and generate data in ionic 4 list using angular 我的侧边菜单使用 Angular 在 Ionic4 下覆盖了我主页的 html 内容 - My side menu overrides my home page's html content under Ionic4 using Angular Angular Firestore如何检索子集合文档进行编辑? - Angular Firestore How do I retrieve a sub collection document for editing? 社交分享 Ionic4 Angular 8 - SocialSharing Ionic4 Angular 8 如何使用Angular Firestore检索子集合? - How can I retrieve a subcollection using Angular Firestore?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM