I am trying to figure out how to filter products based on their sub child nodes in Firebase.
My setup is as follows:
products/
product1
/author: 12345
/title: "Awesome"
/description: "more awesome"
product2
/author: 67890
/title: "Awesome"
/description: "more awesome"
How can I query Firebase such that I retrieve only the products for which it holds that child($productId).child(author)
equals 12345
?
I tried the following, but that obviously does not work. I need a way to filter on the subchild:
var ref = new Firebase(FBURL);
// Attach an asynchronous callback to read the data at our posts reference
ref.child("products").child('$productId').child('author').equalTo(12345).on("value", function(snapshot) {
console.log(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
Simply use
orderByChild()
:This will order every child node under
products
by itsauthor
property and then return only the ones that have a value of12345
.See Firebase's documentation on queries.