且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

一个应用程序中有多个Firebase项目

更新时间:2023-11-22 16:56:46

我建议您将所有社区保持在一起.首先,因为我不太确定您是否可以在同一应用程序中使用多个Firebase项目.

I recommend you to keep all the communities together. First, because I'm not really sure that you can use multiple Firebase Projects in the same app.

我建议您将此社区"及其所有当前信息存储为数据库中的项目.例如:

I suggest you to store this "communities" as items in your database with all their current info. For example:

{
    "Communities":{
            "CommunityKey1":{
                "communityName":
                "createdDate":
                ....
            }
            "CommunityKey2":{
                "communityName":
                "createdDate":
                ....
            }
            "CommunityKey3":{
                "communityName":
                "createdDate":
                ....
            }
            ....
        }
}

当您将用户添加到数据库时,只需向他们添加一个关联的字段"currentCommunity"或类似的东西,您可以在其中存储该用户的关联的CommunityID.然后,当您想为一个社区过滤用户时,只需使用:

And when you add your users to your database, just add them an associated field "currentCommunity" or something like that where you store the associated communityID for that user. Then, when you want to filter the users for one community just use:

FirebaseDatabase.getInstance().getReference().child("users").child("currentCommunity");

您可以在该查询的末尾使用.equalTo("CommunityID")过滤其他内容.我不是Firebase方面的专家,但是我正在做一个具有类似用户过滤功能的应用程序(使用组而不是社区,它们可以属于多个用户),而做到这一点的***方法是使用此模型.

You can filter else more using .equalTo("CommunityID") at the end of that query. I'm not an expert in Firebase, but I'm doing an app with a similar kind of user filtering(using groups instead of communities and they can belong to more than one), and the best way to do this was using this model.

希望它将对您有所帮助!祝你好运!

Hope that it will help you! Good luck!