我从firebase开始,我遇到了数据查询问题。我有这个firebase数据库:
"Conversations" : {
"-L9LJQiFKqGlNKKFEyvd" : {
"-L9LJQiHrp1rU1pblNG_" : {
"messageText" : "Hi there",
"postTime" : 1522940321427,
"senderId" : "GSJMlFA3pYMjYCfY6BA0AEyva9u2",
"senderNickname" : "q"
},
"-L9LZ0O2rXHe-eh2iRgB" : {
"messageText" : "f",
"postTime" : 1522944447238,
"senderId" : "GSJMlFA3pYMjYCfY6BA0AEyva9u2",
"senderNickname" : "q"
},
"-L9LZ7uF9TPb4VZ-wJEO" : {
"messageText" : "vvvv",
"postTime" : 1522944478035,
"senderId" : "GSJMlFA3pYMjYCfY6BA0AEyva9u2",
"senderNickname" : "q"
}
}
},
我想显示对那些“postTime”值高于某个特定值的push()对象的引用,例如:1522944447230。 我试过了:
mConversationId = "-L9LJQiFKqGlNKKFEyvd"
mLeaveTime = 1522944447230;
mUserConversationsReference = mFirebaseDatabase.getReference().child("Conversations");
mUserConversationsMessagesReference = mUserConversationsReference.child(mConversationId);
mLastMessageQuery = mUserConversationsMessagesReference.orderByChild("postTime").orderByValue().startAt(mLeaveTime);
然后我得到:
java.lang.IllegalArgumentException:您无法组合多个orderBy 来电!
所以必须有另一种方法来解决这个问题。我会很感激任何建议。
答案 0 :(得分:0)
要解决此问题,请使用代码行:
String mConversationId = "-L9LJQiFKqGlNKKFEyvd"
long mLeaveTime = 1522944447230;
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mConversationIdRef = rootRef.child("Conversations").child(mConversationId);
Query query = mConversationIdRef.orderByChild("postTime").startAt(mLeaveTime);
.orderByValue()
在此查询中与您无关。请注意,Firebase不允许您使用多个orderBy调用。所以要解决这个问题,只需一个即可。