2017-02-28 70 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

谢谢你们两个! –