Firebase查询帮助 - 双嵌套

时间:2016-01-06 22:27:59

标签: firebase

我正在尝试查询一些看似无法正常通话的数据。

以下是数据的示例:

{
    "currentSelectedPlayers" : {
        "player1" : {
            "assists" : "97",
            "currentlyPickedBy" : {
                "userID" : "641aada9-2d42-4b83-9883-ca316c842a08"
            },
            "goals" : "2",
        }
}

在我的规则中,我设定了:

"rules": {
"$currentSelectedPlayers": {
         ".indexOn": ["currentlyPickedBy", ".value"]
       }
}

我的查询:https://{database-address}.firebaseio.com/currentSelectedPlayers.json?orderBy="$value"&equalTo="641aada9-2d42-4b83-9883-ca316c842a08"&print=pretty

我知道firebase最近引入了对深层嵌套数据的查询。我如何正确查询此嵌套数据?

1 个答案:

答案 0 :(得分:2)

您不需要.value索引,而是路径``:

上的索引
{ 
  "currentSelectedPlayers": { 
    ".indexOn": ["currentlyPickedBy/userID"] 
  }
}

然后您可以使用以下方式查询:

currentSelectedPlayers.json?orderBy="currentlyPickedBy/userID"&equalTo="641aada9-2d42-4b83-9883-ca316c842a08"&print=pretty

在这里给它一个旋转: https://stackoverflow.firebaseio.com/34644066/currentSelectedPlayers.json?orderBy=%22currentlyPickedBy/userID%22&equalTo=%22641aada9-2d42-4b83-9883-ca316c842a08%22&print=pretty