I have a real-time database in firebase I am talking to with an android app. This is an example of the documents I have
[
{
"CampsiteKey": 1,
"UserRating": 0.9,
"mAuth": "hP9kaoV5IRTEZZG51viaRPfPZS73"
},
{
"CampsiteKey": 2,
"UserRating": 3,
"mAuth": "hP9kaoV5IRTEZZG51viaRPfPZS73"
},
{
"CampsiteKey": 3,
"UserRating": 4,
"mAuth": "hP9kaoV5IRTEZZG51viaRPfPZS73"
},
{
"CampsiteKey": 4,
"UserRating": 1.7,
"mAuth": "test user"
}
]
In android I am developing with java. What I want to do is do a query and have it match mutliple key value pairs, although I am not having much success. i have done this to get by:
private void QueryUserRating(String camp_key,String uid)
{
//Now lets get the campsite and hold onto that into a global
Query query = FirebaseDatabase.getInstance().getReference("UserRatings")
.orderByChild("mAuth")
.equalTo(uid)
.limitToFirst(1);
query.addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange (DataSnapshot dataSnapshot)
{
if (dataSnapshot.exists())
{
//We have data for the user, now check if it matches the camp key
for(DataSnapshot snapshot: dataSnapshot.getChildren())
{
DisUserRating = snapshot.getValue(UserRating.class);
UserRatingKey = snapshot.getKey();
//We have a site that matched auth/user, now see if the camp id matches
if( 0== DisUserRating.CampsiteKey.compareTo(camp_key))
{
UpdateCampUIData();
}
else
{
DisUserRating=null;
UserRatingKey=null;
}
}
}
else
{
//They never had a user rating so just set it to naught
DisUserRating = new UserRating(camp_key,(float)0.0,mAuth.getUid());
UserRatingKey=null;
}
}
@Override
public void onCancelled (DatabaseError error)
{
//TODO filll this out with a toast
}
});
}
So in the loop I am forced to look at the returned documents and then filter in there based on the camp_key. What I was really hoping to do was this:
Query query = FirebaseDatabase.getInstance().getReference("UserRatings")
.equalTo(uid,"mAuth")
.equalTo(camp_key, "CampsiteKey")
.limitToFirst(1);
Then I would get back one record matching these two keys with their values. However I end up getting this runtime error
java.lang.IllegalArgumentException: Cannot combine equalTo() with startAt() or startAfter()
Any help would be appreciated. I basically want to do the same as Where= for multiple values. I am a novice at this so anything that can get me to get this to work would be great.