I'm building ticketing app using Firebase Database. Here's my database format:
if I write the code like this:
let ref = FIRDatabase.database().reference()
ref.child("jadwal")
.queryOrderedByChild("tanggal")
.queryEqualToValue("17/08/2016")
.observeEventType(.ChildAdded, withBlock: { (snapshot) in
print(snapshot)
}, withCancelBlock: nil)
the output will be:
Snap (-KPMQefHSuk7j9kb3GTJ) {
asal = BNA;
harga = 177000;
idBus = id;
jam = "20:00";
tanggal = "17/08/2016";
tersedia = 35;
tujuan = BRN;
}
Snap (-KPMQnCGrXY36NEMxSOU) {
asal = BNA;
harga = 150000;
idBus = id;
jam = "20:00";
tanggal = "17/08/2016";
tersedia = 37;
tujuan = MDN;
}
Snap (-KPMQqFmku_XzItElzjV) {
asal = BNA;
harga = 160000;
idBus = id;
jam = "20:00";
tanggal = "17/08/2016";
tersedia = 40;
tujuan = MDN;
}
it will show all the "tanggal" with the value equal to "17/08/2016", when i do this...
let ref = FIRDatabase.database().reference()
ref.child("jadwal")
.queryOrderedByChild("harga")
.observeEventType(.ChildAdded, withBlock: { (snapshot) in
print(snapshot)
}, withCancelBlock: nil)
it will show all the "harga" ordered from low to high like this:
Snap (-KPNgVeXXnqnzevh5w6u) {
asal = BNA;
harga = 120000;
idBus = id;
jam = "22:30";
tanggal = "30/08/2016";
tersedia = 38;
tujuan = TKG;
}
Snap (-KPMQnCGrXY36NEMxSOU) {
asal = BNA;
harga = 150000;
idBus = id;
jam = "20:00";
tanggal = "17/08/2016";
tersedia = 37;
tujuan = MDN;
}
Snap (-KPMQqFmku_XzItElzjV) {
asal = BNA;
harga = 160000;
idBus = id;
jam = "20:00";
tanggal = "17/08/2016";
tersedia = 40;
tujuan = MDN;
}
Snap (-KPMQefHSuk7j9kb3GTJ) {
asal = BNA;
harga = 177000;
idBus = id;
jam = "20:00";
tanggal = "17/08/2016";
tersedia = 35;
tujuan = BRN;
}
Snap (-KPNgJPRlEuu0FZvjU2J) {
asal = BNA;
harga = 180000;
idBus = id;
jam = "21:30";
tanggal = "25/08/2016";
tersedia = 40;
tujuan = MDN;
}
Snap (-KPNgQ2qQXQpY4eT2Jqd) {
asal = BNA;
harga = 230000;
idBus = id;
jam = "22:30";
tanggal = "30/08/2016";
tersedia = 38;
tujuan = BNJ;
}
see that the "harga" is sorted but i need to show the list of snapshots which shows "harga" is sorted and only "tanggal" is "17/08/2016". i'm always failed to do this and the error mostly with "multiple orderBy()", i need to query and filter data based on two or more child values. Basically I want to sort based on "harga", filter based on "tanggal", "asal", "tujuan", and minimun number of "tersedia" Please help me i want to switch my db from SQL to Firebase. Thank you.