1

I have the following Realtime Database structure

DB 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

1 Answer 1

2

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());
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.