Firebase .indexOn动态键不起作用

问题描述 投票:0回答:1

我有这个结构:

conversations:
   -439f6b3c0958:
        -messages:...
            -users:
                -ccb756c0:
                     -userId: ccb756c0
                     ...

我正在尝试通过对话/ {someid} /用户节点内的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"
                  }
          }
    }
}

谁应该编写此规则以匹配我正在使用的结构?

android firebase firebase-realtime-database firebase-security
1个回答
0
投票

您需要在运行查询的级别上定义索引。现在,您的水平太低了。

所以应该是:

"conversations": {
    "$conversationId":{
          "users" :{
              "userId": {".indexOn": ".value"}
          }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.