【发布时间】:2017-08-03 15:35:12
【问题描述】:
我在 Realtime DB 中有超过 2000 种产品。可以看到产品结构 下面
但问题是我需要使用 3 个 WHERE 子句进行查询。
我需要获取 CID = C09 && MID= S03 && SID= S03 的项目
我已经提到了下面的问题Query based on multiple where clauses in firebase
我已经研究了第一个解决方案。但是C09类有1000多个产品。我正在下载 1000 个产品以显示 20 个产品。
我尝试使用查询库。但它有一个issue。
所以请给我一个有效的查询解决方案。
代码
var firstCat = firebase.database().ref('S01/Products').orderByChild("productCID").equalTo("C09");
firstCat.once("value")
.then(function (snapshot) {
snapshot.forEach(function (childSnapshot) {
var key = childSnapshot.key;
var MID = childSnapshot.child("productMID").val();
var SID = childSnapshot.child("productSID").val();
if (MID == "M03" && SID == "S03") {
var ProductID = childSnapshot.child("productID").val();
var name = childSnapshot.child("productName").val();
var unit = childSnapshot.child("productUnit").val();
var status = childSnapshot.child("productStatus").val();
var productMRP = childSnapshot.child("productMRP").val();
var price = childSnapshot.child("productSellingPrice").val();
var buying_price = childSnapshot.child("productBuyingPrice").val();
}
});
});
【问题讨论】:
标签: javascript firebase firebase-realtime-database nosql