在Firebase中加入两个节点 [英] Join two nodes in Firebase

查看:63
本文介绍了在Firebase中加入两个节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序应该显示来自两个节点(Firebase)的数据. Firebase DB的结构为:

I'm working on an app, which is supposed to show data from two nodes(Firebase). Firebase DB is structured as:

{
    "College": {
        "4F2EAB65": {
            "id": "4F2EAB65",
            "name": "SomeCollege"
        },
        "A3C2ED31": {
            "id": "A3C2ED31",
            "name": "OtherCollege"
        },
        "F967B5A0": {
            "id": "F967B5A0",
            "name": "CoolCollege"
        }
    },
    "Student": {
        "3E20545B": {
            "college-ID": "4F2EAB65",
            "id": "3E20545B",
            "name": "A"
        },
        "6FDEE194": {
            "college-ID": "F967B5A0",
            "id": "6FDEE194",
            "name": "B"
        }
    }

我想获取具有以下详细信息的学生详细信息:"id",名称",学院ID",学院名称"(需要通过学院ID"获取学院名称").

I want to fetch student details having details: "id", "name", "college-ID", "college-Name"(Need to fetch "college-Name" by "college-ID").

我已经在前端使用for循环实现了这一点.有什么方法可以在Firebase服务器上实现这一目标,我们还可以进行联接(SQL)之类的事情吗?

I've achieved this using for loop at front end. Is there any way to get this achieved at Firebase server, also can we make something like join (SQL).

谢谢.

推荐答案

Firebase实时数据库中不支持服务器端连接.客户端加入是很正常的.

There is no support for server-side joins in the Firebase Realtime Database. Client-side joins are quite normal.

另一种选择是在写入时复制数据,这样就不必从两个位置读取数据.

The alternative is to duplicate the data upon writing, so that you don't have to read from two locations.

最适合您的应用程序的是个人喜好,所涉及的代码与数据重复的舒适度以及应用程序的用例.

What's best for your application is a matter of personal preference, your comfort level with the code involved vs data duplication, and the use-cases of your app.

客户端Jon​​可能没有您想象的那么慢.参见

Client-side jons are likely not as slow as you may think. See http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786

这篇关于在Firebase中加入两个节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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