2017-02-28 41 views
3

以下是我的Firebase數據庫結構和我的查詢。Firebase索引動態值警告

enter image description here

而且我對這種結構的查詢是:

var messageRef = databaseRef.child(`/messagesThread/-KdzCvVW5icW7ZuSIAxV`); 

messageRef.orderByChild(`/readBy/{userId}`).equalTo(false).on("child_added", (snapshots)=>{ 
    console.log("Unread messages = " + snapshots.numChildren()); 
}); 

但上面的查詢給我的警告作爲

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "readBy/{userId}". 

因此,如何增加這個indexOn動態{userId}

回答

3

由於在通配符索引不是很大,你可以修改結構,然後指數:

---readBy-+ 
      | 
      294jjfouurjkfJDGLS+ 
          | 
          isRead: true 

現在,您可以添加到安全規則:

"readBy": { 
    ".indexOn": "isRead" 
} 
+1

是啊。另請參閱我的答案在這裏更長的解釋:http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value –

+0

謝謝你們兩個! –