简体   繁体   English

Firebase JSON树结构

[英]Firebase JSON Tree Structure

I have created a project involving students at schools. 我创建了一个涉及学校学生的项目。 As I have started to build this project I have encountered three major questions: 在开始构建此项目时,我遇到了三个主要问题:

1) Which JSON tree structure is recommended or better? 1)建议使用哪种JSON树结构或更佳?

schools

  grades

    users(uids)

      info

or 要么

users(uids)

  info (includes school and grade)

2) If I were to use the first structure, how would I access the user's grade and school, which is vital to be able to access the rest of the user's contact information, upon first logging in? 2)如果要使用第一个结构,我将如何访问用户的年级和学校,这对于首次登录后能够访问用户的其余联系信息至关重要?

3) If I were to use the second structure, wouldn't it be too many users to query through to find all the people in one grade of one of many schools? 3)如果我要使用第二种结构,不是要查询太多的用户来查找许多学校之一的一个年级中的所有人员吗?

Somebody please help. 有人请帮忙。 At this point, I'm just super confused. 在这一点上,我只是超级困惑。

Before getting Into it mark some points which are best practices for firebase :- 在进入它之前,请先指出一些关于Firebase的最佳做法:

  • Avoid nesting data 避免嵌套数据
  • Flatten data structures 扁平化数据结构
  • Create data that scales 创建可扩展的数据
  • Turn on the persistace storage so that you can query data from local storage which will be fast enough to make user experiance better 打开持久性存储,以便您可以从本地存储查询数据,这将足够快以使用户体验更好

    for more info - check this link 有关更多信息, 请检查此链接

  • I feel below JSON structure will be nice. 我觉得下面的JSON结构会很好。 I'm not sure of it as I don't know exact requirement of yours. 我不确定,因为我不知道您的确切要求。 It depends on your requirement. 这取决于您的要求。 But always the recommended way is to try to create more independent nodes as you can access data through queries. 但始终建议的方法是尝试创建更多独立的节点,因为您可以通过查询访问数据。

    schools
    
       users(uids)
    
          Grades or info based on relation between grades and users
    

    Just make separate nodes for user's info, and the other node for member of grade of school 只需为用户信息创建单独的节点,为学校年级成员创建另一个节点

    schooldb
    
       schools
    
          grades
    
             users(uids)
    

    and for getting info 并获取信息

    userdb
    
     users(uids)
    
        info (includes school and grade)
    

    This is a necessary redundancy for two-way relationships 这是双向关系的必要冗余

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM