Firebase multiple WHERE clause in query
The Realtime Database does not support multiple where clauses but you can create an extra key to make it possible.
A "flight" in your "flight"
list can have a combined key for "arrivalDate"
and "code"
.
"1ddf3c02-1f2e-4eb7-93d8-3d8d4f9e3da2" : {
"airport" : "Gothenburg, Sweden - Landvetter (GOT)",
"arrivalDate" : "2016-06-21",
"arrivalTime" : "20:58",
"arrivalDate_code": "2016-06-21_GOT", // combined key
"code" : "GOT",
"departureDate" : "2016-06-23",
"departureTime" : "20:58"
}
Then you can query for that key.
Firebase ref = mFirebaseRef.child(FirebaseReference.CHILD_FLIGHTS);
Query queryRef = ref.orderByChild("arrivalDate_code").equalTo("2016-06-21_GOT");
queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
});
Another option is to key off of a field in the data structure:
/ flights
/ $code
/ $flight_id
This means your data would look like this:
"flight" : {
"GOT": {
"1ddf3c02-1f2e-4eb7-93d8-3d8d4f9e3da2" : {
"airport" : "Gothenburg, Sweden - Landvetter (GOT)",
"arrivalDate" : "2016-06-21",
"arrivalTime" : "20:58",
"code" : "GOT",
"departureDate" : "2016-06-23",
"departureTime" : "20:58"
}
}
}
And then you could formulate a query like this:
Firebase ref = mFirebaseRef.child(FirebaseReference.CHILD_FLIGHTS);
Query queryRef = ref.child("GOT").orderByChild("arrivalTime").equalTo("2016-06-21_GOT");
queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
}
});