0

Please assume following structure:

/parentNode
     / ...
     /childNode <-- I only want this KEY without retrieving childChildNodes
         /childChildNode
         /childChildNode
         /...andManyManyMoreChildChildNodes...
     /childNode <-- by limitToFirst(2) I maybe also want this KEY but again without retrieving all the rest
         /childChildNode
         /childChildNode
         /...andManyManyMoreChildChildNodes...
     /...andManyManyMoreChildNodes...
         / ...

I came to something like this:

let child = "1500127452209";
const findDateRef = firebase.database().ref("parent/");
findDateRef.orderByKey().startAt(child).limitToFirst(2).once('value', snap => {
    console.log("result I want", Object.keys(snap.val()));
    console.log("data retrieved", snap.val());
});

The first log represents the result I want but the second log shows that all the uneeded data was retrieved and filtered on the client which is not what I want.

So how do I stop Firebase from reading child nodes?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Schmalitz
  • 420
  • 1
  • 8
  • 16

1 Answers1

1

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

Denormalization is normal with the Firebase Database - Firecasts

The Firebase Blog: Denormalizing Your Data is Normal

Jen Person
  • 7,356
  • 22
  • 30