Firebase数据库结构-用户,组和列表 [英] Firebase Database Structure - Users, Groups and Lists

查看:123
本文介绍了Firebase数据库结构-用户,组和列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划将一个移动应用程序使用Firebase作为其数据库/身份验证提供程序,主要是因为我发现身份验证确实很容易实现,而且还因为应用程序的性质.该应用程序本身以组中的用户为中心.每个组中都有该组中的每个用户都可以访问的数据范围.

I am planning a mobile application to use Firebase as its database/authentication provider mainly because I have found the authentication really easy to implement and also because of the apps nature. The app itself revolves around users in groups. Within each group is a range of data that will be accessible by every user in that group.

我想对拟议的Firebase数据库结构提供一些反馈,如果有什么我应该做不同的事情或者可以做的更好.

I am wanting some feedback on my proposed firebase database structure and if there is anything I should do differently or could do better.

当前建议的结构:

{
    "users": {
        "userID": {
            "userName": ...
            "email": ...
            "group": groupID
            "creationTime": ...
        }
    },

    "groups": {
        "groupID": {
            "name": ...
            "members": {
                "userID": true
                "userID": true
            }
        }
    },

    "lists": {
        "groupID": {
            "name": ...
            "items": {
                "itemID": true
                "itemID": true
            }
        }
    },

    "items": {
        "itemID": {
            "name": ...
            "createdBy": userID
            "timeCreated": ...
        }
    }
}

以下是我想澄清的几件事:

Here are a few things I want to clarify:

分隔列表和组是明智的选择还是应该将项目嵌入每个列表对象中?

我可以使用groupID作为组和列表的标识符吗,因为每个组只有一个列表链接?这意味着我可以轻松地从用户访问此列表"组"变量.

Am I okay using groupID as the identifier for both the groups and lists seeing as there will only be one list linked to each group? This was means I can easily access this list from the users "group" variable.

推荐答案

Firebase数据库文档建议保持数据平坦,而不是嵌套无关的数据类型.看来您正在尝试这样做,听起来不错.

The Firebase Database documentation recommends keeping your data flat, not nesting unrelated types of data. It seems you're trying to do that, so that sounds good.

如果将数据拼合,则需要一种将各个列表中的项目相互关联的方法.最简单的方法是在所有列表中为对应的项目赋予相同的键.它们就像关系数据库中的PK/FK,只是Firebase(与大多数关系DBMS不同)不为您管理关系.

If you flatten your data, you will need to have a way to relate items in the various lists with each other. The simplest way to do that is by giving the corresponding items the same key in all lists. They're like PK/FK in a relational database, except that Firebase (unlike most relational DBMSs) doesn't manage the relation for you.

数据建模的主题范围之广令人难以置信,而且很难以Q& A格式来做到这一点.我强烈建议阅读 NoSQL数据建模并查看我们的 SQL开发人员的Firebase 系列.您还会在此列表中找到很多数据建模问题.

The topic of data modeling is incredibly broad and it's hard to do it justice in a Q&A format. I highly recommend reading NoSQL data modeling and viewing our Firebase for SQL developers series. You'll also find a lot of data modeling questions in this list.

这篇关于Firebase数据库结构-用户,组和列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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