Reputation: 13
I have the following Realtime Database structure
Now I want to query the aeds by their owner so that the query returns all aeds (with children) with the matching owner id.
But somehow I am not capable to do it although I feel it must be easy. Here is the code I have:
var aedRef = dbRef.ref().child("aeds")
var query = aedRef.orderByChild("owner").equalTo(userID);
console.log(query);
I feel that it should be easy but somehow I can't get it working. All I get is this:
e {repo: e, path: e, Me: e, Le: true}
Any help is greatly appreciated
Upvotes: 1
Views: 988
Reputation: 2173
query
is just a document reference, it is not the result of the query. You need to use .on
or .once
on it to get it to return data.
Check the Firebase docs for more info on how to read and write data.
var aedRef = dbRef.ref().child("aeds");
var query = aedRef.orderByChild("owner").equalTo(userID);
// Get data and keep listening for changes
query.on('value', function(snapshot) {
console.log(snapshot.val());
});
// Only get data once
query.once('value').then(function(snapshot) {
console.log(snapshot.val());
});
Upvotes: 2