The only way is to filter data, you can use limitToFirst()
which would return a limited number of nodes from the beginning of the list, or even you can use limitToLast()
that will retrieve limited number of nodes from the end of the list.
For example:
ref.child(eid).limitToFirst(10).addValueEventListener(object: ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
if(snapshot.exists()){
val user = snapshot.getValue(UserModel::class.java)
}
}
})
Or another way if you want to retrieve a specific value, then you can just use equalTo()
:
ref.child(eid).orderByChild("name").equalTo("Peter").addValueEventListener(object: ValueEventListener {
override fun onDataChange(snapshot: DataSnapshot) {
if(snapshot.exists()){
val user = snapshot.getValue(UserModel::class.java)
}
}
})
The above query would work, if you have the following database:
eid
random_id
name: Peter
Check the following documentation for more information:
https://firebase.google.com/docs/database/android/lists-of-data#filtering_data