Alex Johnson
Alex Johnson

Reputation: 69

Firebase data retrieval without one of the child node

Picture of my database

Hi guys. I got stuck with a problem with firebase database. I wanted to get last two processdata object based on timestamp. I don’t want it to be returned within parent object of processdata, because the requirement is rawdata object which is another child of parent object should not be send to the application side. So getting parent object also get rawdata as it is also child. How can I avoid it? Following code return processdata within parent object as I said

var firebaseHeadingRef6 = firebase.database().ref('pond2/temperature');

firebaseHeadingRef6.orderByChild("{key}/processdata/timestamp").limitToLast(2).on("value", function(snapshot) {
        console.log(snapshot.val());

});

Upvotes: 1

Views: 794

Answers (1)

Daniel Beck
Daniel Beck

Reputation: 21485

You can't. When you load any data from firebase, all its child data comes along for the ride. Emphasis mine:

when you fetch data at a location in your database, you also retrieve all of its child nodes. In addition, when you grant someone read or write access at a node in your database, you also grant them access to all data under that node. Therefore, in practice, it's best to keep your data structure as flat as possible. https://firebase.google.com/docs/database/web/structure-data

Store your rawdata separately from the data that should be sent to the client.

Upvotes: 1

Related Questions