2

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"
        }
    }

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

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).

Thanks.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Vaibhav Parmar
  • 461
  • 4
  • 14
  • 1
    The web is full of examples and tutorials on Firebase join. This is just the first one: https://firebase.googleblog.com/2013/10/queries-part-1-common-sql-queries.html – Palle Due Dec 18 '17 at 13:04
  • One way to could be to implement an indexer. Firebase themselves suggest using Algolia for full text search - https://firebase.google.com/docs/firestore/solutions/search – Chris Edgington Dec 18 '17 at 14:28

1 Answers1

0

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.

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807