gpt4 book ai didi

javascript - firebase indexOn 用于子值

转载 作者:太空宇宙 更新时间:2023-11-03 22:23:06 27 4
gpt4 key购买 nike

我正在尝试使用 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 WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "post/vote/moodTags/M1/key" at /Recommendations to your security rules for better performance.

但是,我在 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
...

最佳答案

您似乎操作的级别太深了:毕竟您想要索引心情标签列表,而不是一个心情标签的内容。

这意味着您的规则必须看起来更像这样:

"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 .

关于javascript - firebase indexOn 用于子值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51200459/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com