2017-04-15 20 views
0

enter image description here如何編寫.indexOn for firebase中的嵌套值?

我已經寫了下面的規則獲取價值形式與密鑰createdAt聊天但我無法從Firebase DB中獲取值。規則如下

"chats": { 
    ".read" : true, 
    ".write" : "auth !== null", 
     "messages" : { 
      ".indexOn": ["userName", "createdAt", "userId"] 
     } 
}, 

聊天/ messages.json ORDERBY = 「createdAt」 & startAt = 1485920224250 &打印=漂亮

+0

莫非你請編輯你的原始帖子,以澄清你的問題是什麼?您的標題顯示您想要編寫規則以在Firebase中爲嵌套值編制索引,但稍後在您的文章中稱您無法獲取值。如果您沒有從Firebase返回數據,則還有其他問題。 –

+0

我已經寫了聊天/ messages.json的規則?orderBy =「createdAt」&startAt = 1485920224250&print = pretty,但firebase does not return anything,kindly advice me what rules requires need in firebase –

回答

2

你錯過了規則中的一個級別:?

"chats": { 
    ".read" : true, 
    ".write" : "auth !== null", 
    "$chatId": { 
     "messages" : { 
      ".indexOn": ["userName", "createdAt", "userId"] 
     } 
    } 
}, 
+0

我已經嘗試過您的解決方案,但它會拋出一些對於路徑\「/聊天/消息\」,對規則「 } –

+0

錯誤{」錯誤「:」索引未定義,添加\「。indexOn \」:\「createdAt \」是的,我現在看到你正試圖根據聊天室中的消息時間戳來獲取聊天室。這是行不通的。如果您想按照上次更新的時間順序獲取聊天室,則必須在聊天室上擁有一個屬性,以指示上次更新的時間。 –

+0

@FrankvanPuffelen,但是如何索引聊天和消息? –