条件属性嵌套时如何查询Firebase数据库对象? [英] How to query Firebase database object when criteria property is nested?

查看:52
本文介绍了条件属性嵌套时如何查询Firebase数据库对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firebase数据库中具有以下结构:

I have the following structure in Firebase database:

root
 - Users
 - Posts
   - -K_54s1smPPh6qN4znuT
     - key1: val
     - key2: val
     - User:
       - -K_54sSomeKeyFromUsersObject: "John Doe"
...

但是我在文档中找不到任何示例,当我具有这样的结构时,如何通过UserKey获取所有Posts.

But I can't find any example in documentation how can I fetch all Posts by UserKey when I have structure like this.

我需要有关如何进行查询以比较像这样的嵌套数据的帮助吗?

I need help on how to make a query to compare nested data like this?

推荐答案

一种解决方法是将对帖子的引用保存到用户上.像这样:

One way to approach this is to save the reference to the posts on the user. Like this:

root
 - Users
   - [UserID]
      - UserPosts
        -K_54s1smPPh6qN4znuT
 - Posts
   - -K_54s1smPPh6qN4znuT
     - key1: val
     - key2: val
     - User:
       - -K_54sSomeKeyFromUsersObject: "John Doe"
...

因此,当您要按用户检索所有帖子时,只需查看用户个人资料上的引用

So when you want to retrieve all posts by an user, you just look at the references on the user profile

这篇关于条件属性嵌套时如何查询Firebase数据库对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆