我正在尝试使用firebase查询获取所有心情等于M1的帖子,如下所示:
db.ref(`Recommendations`).orderByChild(`post/vote/moodTags/${idMood}/key`).equalTo(`${idMood}`).once('value').then(recs =>{
//Número de recs con el mood
let recsCount = recs.numChildren();
console.log(`Número de recs encontradas --> ${recsCount}`);
...
});
和Firebase控制台显示警告:
FIREBASE警告:使用未指定的索引。您的数据将在客户端上下载并过滤。考虑在/ Recommendations的安全规则中添加“ .indexOn”:“ post / vote / moodTags / M1 / key”,以提高性能。
但是,我在firebase网站上的索引编制规则是:
"Recommendations":{
".indexOn": ["post/userFirebaseKey","post/user/firebaseKey","userFrom/firebaseKey","post/location/placeId","firebaseKey","placeId"],
"post":{
"vote":{
"moodTags":{
"$moodId":{
".indexOn": "key"
}
}
}
}
}
那么,当我使用子级别时,如何实际指定indexOn规则?
我的数据库:
+ Recommendations
+ idRec
property1:''
property2:''
property3:''
+ post
property21:''
...
+ vote
+ moodTags
+ M1
key:'M1'
name:''
url:''
+ M2
...
答案 0 :(得分:0)
您似乎在此处操作的层次太深:毕竟,您只想索引心情标签的列表,而不是 one 心情标签的内容。
这意味着您的规则必须看起来像这样:
"Recommendations":{
".indexOn": ["post/userFirebaseKey","post/user/firebaseKey","userFrom/firebaseKey","post/location/placeId","firebaseKey","placeId"],
"post":{
"vote":{
"moodTags":{
".indexOn": "key"
}
}
}
}
}
您可以在the official Google Firebase Docs,this helpful article on Medium和this Google Groups post where someone had a similar issue中阅读这些索引编制规则。