I want to get the total number count until specified.
this is my database: database picture
I want to count where ticket_status
is not served
ex: I want to count until A6
, I will count A1
until A5
where the value of ticket_status"
is not served
. so the final count will be 3.
is there any filtering kind?
I have this code but it just counts all nodes with the value of "not served"
dbref.child("Queue").child(a.value.toString()).orderByChild("ticket_status").equalTo("not served").addValueEventListener(object : ValueEventListener{
override fun onDataChange(snap: DataSnapshot) {
val count = snap.childrenCount
dbref.child("Student_Queue_Reserve").child(idNumber.toString()).child("people_ahead").setValue((count-1).toString())
}
override fun onCancelled(error: DatabaseError) {
}
})
2
Answers
There is no way you can do that in the Realtime Database because queries can only order/filter on a single property. There are cases in which you can combine the values you want to filter into a single property. For example, please check my answer below:
If you’re allowed to change the database schema, then you should consider denormalizing the data. So a structure like below will do the trick:
Now you can query the "not served" node, using a combination of Query#orderByKey() and Query#endAt(java.lang.String)
You can try this approach without query:
And for count you can use :