我正在尝试获取Firebase的一些数据。我想做orderby()。equalTo()但我总是在查询中得到null。我尝试过两个值deliverBy(boolean)和deliverBy(long)。
查询
queryFirebase = FirebaseDatabase.getInstance().getReference().child("rooms").orderByChild("read").equalTo(false);
queryFirebase.addListenerForSingleValueEvent(new ValueEventListener() {
将我的消息发送到Firebase
Long userId = ApplicationConfig.getCurrentUser().getId();
String toServerUnicodeEncoded = StringEscapeUtils.escapeJava(etMessage.getText().toString());
MessageFirebase message = new MessageFirebase(toServerUnicodeEncoded, new DateTime().toString("yyyy-MM-dd'T'HH:mm:ss'Z'"), userId);
DatabaseReference messageRef = mFirebaseDatabaseReference.push();
messageRef.setValue(message);
MY JSON
{
"rooms" : {
"-KtMBWKEf7-Ot8HdMtbd" : {
"-KtMC7CglZZ-Yp4_PQOU" : {
"blocked" : false,
"createDate" : "2017-09-06T14:40:17Z",
"delivered" : false,
"deliveredBy" : 317,
"difDays" : 0,
"isBlocked" : false,
"message" : "hola",
"read" : false
},
"-KtMCCdbKzP7UKFTB_qG" : {
"blocked" : false,
"createDate" : "2017-09-06T14:40:39Z",
"delivered" : false,
"deliveredBy" : 317,
"difDays" : 0,
"isBlocked" : false,
"message" : "que tal",
"read" : false
},
"commerceId" : 218,
"userId" : 317
}
}
}
答案 0 :(得分:2)
read
不是rooms
你应该做
queryFirebase = FirebaseDatabase.getInstance().getReference()
.child("rooms")
.child("-KtMBWKEf7-Ot8HdMtbd")
.orderByChild("read")
.equalTo(false);
queryFirebase.addListenerForSingleValueEvent(new ValueEventListener() {