Android Firebase.indexOn动态键不工作
我有这样的结构:Android Firebase.indexOn动态键不工作,android,firebase,firebase-realtime-database,firebase-security,Android,Firebase,Firebase Realtime Database,Firebase Security,我有这样的结构: conversations: -439f6b3c0958: -messages:... -users: -ccb756c0: -userId: ccb756c0 ... 我试图通过会话/{someid}/users节点内的userId查询会话 Firebase sdk向我发出此警告,这对性能非常不利 Using a
conversations:
-439f6b3c0958:
-messages:...
-users:
-ccb756c0:
-userId: ccb756c0
...
我试图通过会话/{someid}/users节点内的userId
查询会话
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"}
}
}
}
这似乎也不起作用,所以问题可能是我使用的查询
FireBaseConversationsReferance.orderByChild(“users/”+userId+“/userId”).equalTo(userId).addValueEventListener…
正在添加与规则不符的useId?indexOn值必须指向要索引的值的每个子节点下的确切路径。这里有一个通配符/动态值,这是不可能的。您通常需要自己在JSON中创建一个反向索引来实现这一点。请看,我的另一种措辞是,您当前的数据结构使您能够轻松找到对话的用户。然而,这并不能让用户轻松找到对话。为此,您需要添加一个反向数据结构,从/user\u conversations/$uid/$conversationId
开始,它似乎可以在较小的数据量下正常工作,并将对其进行可伸缩性测试,这是我以前的原始方法。谢谢你的大力帮助@Frank