0

I have a Firebase real-time database structured as such:

{
    product : {
        "book1" : {
            "name" : "LoTR",
            "category" : {
                "Fiction" : true
            }
        }
    }
    genre : {
        "Fiction" : {
            "name" : "Fiction",
            product : {
                "book1" : true
            }
        }
    }
}

I was wondering if I should also add a key-key table like:

genre_product : {
    -3i9wfiosdniov : {
        "book1" : "Fiction"
    }
}

To make relations and use the $key : true for integrity check? Is one way of making relations better than the other or is it just by Use Case?

1 Answers1

0

Firebase Database has no concept of relations, hence also no concept of relational integrity. Any such concept will need to be handled purely in your (application and server) code, and in the server-side security rules for your database.

As usual in NoSQL database design, there is no one data model that is best. It all depends on the use-cases of your app. For a good introduction I recommend reading NoSQL data modeling and watching Firebase for SQL developers. I also recommend checking out my answers to Many to Many relationship in Firebase and Firebase query if child of child contains a value.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Yup, thats what I meant by relational integrity check. I'll write a loop through and check that they true each other as integrity check, and use the key-key table for queries. Firebase documentation shows both usable for setting up relations, so I was just curious as to the NoSQL convention for "relations". – I should change my Username Nov 07 '18 at 02:22