我的数据库看起来像
{ "chats" : { "-K5hUtxNOPLWwRTb8fAj" : { "clientId" : 893, "messages" : { "-K5hUtyCwWuPeFT0cSXr" : { "chatKey" : "-K5hUtxNOPLWwRTb8fAj", "messageText" : "new message", "timestamp" : 1450314801055, "userId" : "19eaa3f0-4ab3-44b4-b418-03b64ca2313a" }, "-K5hUvwKsAOvuvt-ymFG" : { "chatKey" : "-K5hUtxNOPLWwRTb8fAj", "messageText" : "did this work", "timestamp" : 1450314809127, "userId" : "48f7a208-5647-4d0e-921c-c49595de1db2" } }, "newQuestion" : false, "startedByUserId" : "19eaa3f0-4ab3-44b4-b418-03b64ca2313a" }, "-K5hVKjs4SkSHD7WTh1I" : { "clientId" : 518, "messages" : { "-K5hVNzPKNgxLCgkfInI" : { "chatKey" : "-K5hVKjs4SkSHD7WTh1I", "messageText" : "this is new", "timestamp" : 1450314928109, "userId" : "19eaa3f0-4ab3-44b4-b418-03b64ca2313a" } }, "newQuestion" : true, "startedByUserId" : "19eaa3f0-4ab3-44b4-b418-03b64ca2313a" } } }
我怎样才能得到所有chats
有一个newQuestion
设置为true
?我尝试了几个不同的查询,最新的是:
firebaseDb.child("chats/newQuestion").equalTo(true).once("value"...
但是抱怨布尔需要订单?
您必须先指定一个orderBy
方法.
var query = firebaseDb.child("chats").orderByChild("newQuestion").equalTo(true);
以下是有关查询的Firebase文档.