根据 Firebase 中的子项过滤产品

Filter products based on the sub child in Firebase

我正在尝试找出如何根据 Firebase 中的子节点过滤产品。

我的设置如下:

products/
     product1
        /author: 12345
        /title: "Awesome"
        /description: "more awesome"
     product2
        /author: 67890
        /title: "Awesome"
        /description: "more awesome"

我如何查询 Firebase,以便我只检索它持有的 child($productId).child(author) 等于 12345 的产品?

我尝试了以下方法,但这显然不起作用。我需要一种过滤子项的方法:

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);
});

只需使用orderByChild():

ref.child("products").orderByChild('author').equalTo(12345)...

这将按 author 属性 对 products 下的每个子节点进行排序,然后 return 仅对值为 12345 的子节点进行排序。

Firebase's documentation on queries