0
"vehicles" : {
"-KbwlIGLm6dxffPJoJJB" : {
"fuel" : "petrol",
"groups" : {
"-KdWh_9KVF16efcSdrji" : true,
"-Kdb1G720MDgbuR3nPBL" : true
},
"make" : "Honda",
"model" : "City",
"name" : "Honda City",
"speed_limit" : 100,
"tank_size" : 32,
"type" : "car"
},
"-KdU-BlfEdqzKxFjGI3D" : {
"fuel" : "petrol",
"groups" : {
"-KdWh_9KVF16efcSdrji" : true
},
"make" : "yamaha",
"model" : "FZ",
"name" : "Yamaza FZ",
"speed_limit" : 60,
"tank_size" : 12,
"type" : "bike"
}
}
我想检索结果,其中groups
有-KdWh_9KVF16efcSdrji
,且密钥必须等于true。如何根据布尔值查询Firebase?
vehicles_ref.child("groups").orderByChild("-KdWh_9KVF16efcSdrji").equalTo(true).on
("value", function (snapshot) {
console.log(snapshot.val());
});
但是目前我得到NULL
为上述标准。
我已经改变查询
vehicles_ref.orderByChild("/groups/-KdWh_9KVF16efcSdrji").equalTo(true).on("value", function (snapshot) {
console.log(snapshot.val());
});
现在取得成果,但现在越来越警告
火力警告:使用未指定索引。考虑加入“.indexOn”:‘群/ -KdWh_9KVF16efcSdrji’在/车辆安全规则获得更好的性能
如何添加索引以消除此警告?
你试图把车辆进行分类。虽然您可以为其添加索引,但这意味着您需要为每个类别添加一个新索引。相反,看看我的答案在这里为更好的方式建模类别:http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value –
我们正在运行一个带有此警告的大型系统。我们做得很好。这不是一个错误。 –