我收到一条错误消息:
FIREBASE警告:使用未指定的索引。您的数据将在客户端上下载并过滤。考虑在/ questions的安全规则中添加“ .indexOn”:“ author”,以获得更好的性能。
我的Firebase规则:
"questions": {
".read": true,
".write": true,
".indexOn": ["category,author"]
},
我的Firebase数据:
"questions" : {
"-Ls1LfayKF9TUg20ByPE" : {
"question" : "1",
"timestamp" : 1571997530706,
"author" : "9jNkvzr0chgPi0SC6rXMlVWdOF12"
},
"-Ls1Lj_OG4lo11r3WQzF" : {
"question" : "2",
"timestamp" : 1571997546988,
"author" : "9jNkvzr0chgPi0SC6rXMlVWdOF12"
},
我的代码:
const ref = FirebaseRef.child('questions')
ref.orderByChild('author').equalTo(UID).limitToLast(this.state.limit)
.on("child_added", snapshot => {
console.log("FireB ",snapshot)
var items = [];
snapshot.forEach((child) => {
items.push({
key: child.key,
...child.val()
});
});
答案 0 :(得分:0)
.indexOn
可以是字符串值的数组。您现在实际上那里只有一个字符串值。
所以替换:
".indexOn": ["category,author"]
使用:
".indexOn": ["category", "author"]