android - Firebase .indexOn 动态键不起作用
问题描述
我有这个结构:
conversations:
-439f6b3c0958:
-messages:...
-users:
-ccb756c0:
-userId: ccb756c0
...
我正在尝试通过userId
对话/{someid}/users 节点内部查询对话
Firebase sdk 给了我这个警告,它对性能非常不利
Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding '".indexOn": "users/ccb756c0/userId"' at conversations to your security and Firebase Database rules for better performance
我添加了这条规则,但它没有解决问题
"conversations": {
"$conversationId":{
"users" :{
"$uid":{
"userId": {".indexOn": ".value"}
}
}
}
}
我也试过这个没有运气:
"conversations": {
"$conversationId":{
"users" :{
"$uid":{
".indexOn": "userId"
}
}
}
}
谁应该写这个规则来匹配我正在使用的结构?
解决方案
您需要在运行查询的级别上定义索引。现在你的水平太低了。
所以应该是:
"conversations": {
"$conversationId":{
"users" :{
"userId": {".indexOn": ".value"}
}
}
}