Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Firebase.indexOn动态键不工作_Android_Firebase_Firebase Realtime Database_Firebase Security - Fatal编程技术网

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