Denormalization is normal with the Firebase Database - The Firebase Database For SQL Developers #6

Firebase · 76K views · 2016 · 6:14

Open on YouTube

Databases & storageWeb developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it when answering Firebase questions about joins, queries across related data or structuring the database, as the canonical explanation of why to duplicate data instead of normalizing it.

Recommended by 14 people across 45 different months, 2015 to 2022.

What it is

A six-minute episode of the official Firebase series 'The Firebase Database For SQL Developers', presented by David East. It explains denormalization, meaning duplicating data across the tree to simplify and speed up reads, and why that is normal in NoSQL databases like the Firebase Realtime Database.

What people said

Recommends Salah Saleh · 2015-06 · Stack Overflow · on “MongoDB and "joins"”

The fact that mongoDB is not relational have led some people to consider it useless [LINK] . I think that you should know what you are doing before designing a DB. If you choose to use noSQL DB such as MongoDB, you better implement a schema. This will make your collections - more or less - resemble tables in SQL databases. Also, avoid denormalization (embedding), unless necessary for efficiency reasons. If you want to design your own noSQL database, I suggest to have a look on Firebase [LINK] documentation. If you understand how they organize the data for their service, you can easily design a similar pattern for yours. As others pointed out, you will have to do the joins client-side, except

Recommends idan · 2017-01 · Stack Overflow · on “Best practice for displaying Firebase many-to-many relationships in the view (AngularFire)”

Short answer: denormalize your data. A bit longer answer: You need to save the data in a way that helps you be efficient when you query it. So for this particular case, you could save the tag's name instead of just true which only shows association. So instead of { posts: -K_GOdSQvCQ2sAcHfo1x: { descpripton: "This is a post...", title: "This is a title...", tags: { -K_aBTTDKVUovZe3l0lX: true } } } You could save it like { posts: -K_GOdSQvCQ2sAcHfo1x: { descpripton: "This is a post...", title: "This is a title...", tags: { -K_aBTTDKVUovZe3l0lX: "Sport" // <----- Notice the change } } } Watch this [this video] (and others, like this playlist [LINK] ) videos from the official Firebase chanel. Extrem

Recommends Yaroslav Mytkalyk · 2017-03 · Stack Overflow · on “Select IN() query in firebase database android”

I had the exact similar problem retrieving users by IDs. I found that there was no way of making the IN query in Firebase . David suggests in his video [this video] either denormalizing the database or making a query for every id. I did not like denormalizing so I queried every user. If you're in to RxJava, here's what I did @NonNull private Observable<List<User>> userIdsToUsers(@NonNull final List<String> uids) { if (uids.isEmpty()) { return Observable.just(new ArrayList<>()); } return Observable.combineLatest(userIdsToUserObservables(uids), new ListCastFunc<>(User.class)); } @NonNull private List<Observable<User>> userIdsToUserObservables(@NonNull final List<String> uids) { final List<Observabl

Recommends James Poag · 2017-05 · Stack Overflow · on “Can I retrieve queries based on two properties?”

The short answer is no. From the docs: You can only use one order-by method at a time. Calling an order-by method multiple times in the same query throws an error. [LINK] You can limit the Range of data using a filter function: [LINK] Be sure to watch the Firebase for SQL devs [LINK] series. Specifically, the video on denormalization [this video] (#6) and the follow up Multi-path updates (#7). Multipath updates can be performed server side using Cloud function triggers [LINK] .

Recommends Jen Person · 2017-08 · Stack Overflow · on “Do not retrieve children of record”

The structure of the Realtime Database is such that reading from a reference reads all of the data under that reference, including child nodes. If you only need certain parts of the data, that data should have its own node in addition to what is here. As in, you need to denormalize the data. Here are some resources: Documentation- Best practices on structuring the Firebase Realtime Database [LINK] Denormalization is normal with the Firebase Database - Firecasts [this video] The Firebase Blog: Denormalizing Your Data is Normal [LINK]

Recommends ackushiw · 2018-03 · Stack Overflow · on “Firebase dump json data”

It really depends on how you are structuring your JSON. It's generally recommended to make your JSON tree as shallow as possible since all children are loaded when you have a matching query. FIREBASE DATA : { "-id1": { "region": "eu" // bear in mind queries are case sensitive "title": "Foo" "nested": { "city": "berlin" } }, "-id2": { "region": "other" "title": "Bar" "nested": { "city": "berlin" } }, "-id3": { "region": "eu" "title": "Baz" "nested": { "city": "paris" } } } Querying with (using the Android API) .orderByChild("region").equalTo("eu") would return "-id1" and "-id3" with .orderByChild("nested/city").equalTo("berlin") would return "-id1" and "-id2" The REST API Returns Unsorted Res

Recommends Jay · 2018-03 · Stack Overflow · on “Need Inputs for Database Structure in firebase”

This question is way to broad and we don't know what *classified functions* means. Also *normalizing* data is generally the opposite of what makes Firebase (queries) work well. See this video from @davideast Denormalizing is Normal [this video] .It sounds like you want to be able to drill down through states->regions->zones when a user taps each in the UI which should be fairly straightforward but we need more info. If you can clarify the question (a lot) we may be able to make some suggestions.

Recommends Guilherme Lemmi · 2018-04 · Stack Overflow · on “The results are filtered in a multiple query on firebase”

You can use only one orderByChild() clause in your query, so it seems like your second clause is overwritting the first one and you're just getting the ones with request_status===true . From the documentation [LINK] : Queries can only order by one key at a time. Calling orderByChild() multiple times on the same query throws an error My suggestion is to either refactor your current data structure to allow for a simpler query, or use a new third field which concatenates both requests_receiveing_status and request_status , them do your query on this concatenated field. Something like this: { "requests_receiving_status_and_status": "false_true"; } and query it like this: let query = ref.orderByC

Recommends CEO tech4lifeapps · 2018-04 · Stack Overflow · on “How can I set a filter in a FirebaseUI RecylerAdapter when querying the database?”

There is no way to use buildQuery to achieve this. The key to a solution is a strategy called Denormalization , which is a polite way of saying "Duplicating Data" . You may want to watch this for an explanation: Denormalization is normal with Firebase Database [this video] .

Recommends jmdavalos · 2018-10 · Stack Overflow · on “Filter on document reference as a field”

This is one of the instances where it's probably better to denormalize data and duplicate them as needed into other collections. In this case, better to have a copy of `userDetails` and `orgDetails` inside `UserOrg` document. Checkout: [this video]