2016-01-06 94 views
0

我試圖查詢一些數據,看起來似乎沒有得到恰當的調用。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

我知道最近火力推出查詢深嵌套數據。我將如何正確查詢這個嵌套數據?

回答

2

你不需要.value指數,但路徑``一個索引:

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

這裏給它一個旋轉:

{ 
    "currentSelectedPlayers": { 
    ".indexOn": ["currentlyPickedBy/userID"] 
    } 
} 

您可以再與查詢它 https://stackoverflow.firebaseio.com/34644066/currentSelectedPlayers.json?orderBy=%22currentlyPickedBy/userID%22&equalTo=%22641aada9-2d42-4b83-9883-ca316c842a08%22&print=pretty

+0

我標記的答案是正確的,謝謝。如果不是[「currentlyPickedBy/userID」]我有類似[「currentlyPickedBy/{someUserID}」],其中someUserID是動態的,並設置爲true。例如 「currentlyPickedBy」:{ 「641aada9-2d42-4b83-9883-ca316c842a08」:真實, 「867aada9-2d42-4b83-9883-ca316c842a08」:真 } – mopineyro

+0

這是不可能與深路徑查詢,因爲它需要在'.indexOn'中指定路徑。但是,如果您嵌套列表,則應該將其非規範化爲頂級列表。有關嵌套的文檔,請參閱本節:https://www.firebase.com/docs/web/guide/structuring-data.html#section-nested –