"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的结果 .
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());
});
现在得到结果,但现在得到警告
FIREBASE警告:使用未指定的索引 . 考虑在/ vehicle处将“.indexOn”:“groups / -KdWh_9KVF16efcSdrji”添加到您的安全规则中以获得更好的性能
如何添加索引以删除此警告?
1 回答
我也发出警告,我发送了firebase,我在查询中过滤查询,查找具有相同ID的项目 . 警告消息“.indexOn”指的是数据库中的规则,应通过将“.indexOn”添加到您尝试对项目进行排序的组来检查该规则 .
因为恐龙的名字只是关键 . 我们可以在节点/分数中添加.value规则来优化我们的查询:
您可以使用以下链接:https://firebase.google.com/docs/database/security/indexing-data?hl=es-419