Reputation: 39
I am new to Firebase and would like to know how to retrieve all the entries, given one specific value, like names. My db is like this:
{
"-L6wXAM4Yt6OeUx6kLM9" : {
"date" : "Tue Mar 06 14:17:53 GMT-04:00 2018",
"names" : "Raamon"
},
"-L6wXAM84ti-Ea0vzKfx" : {
"date" : "Tue Mar 06 14:17:53 GMT-04:00 2018",
"names" : "Anne"
},
"-L6whnSSZXHxdjPvGgKI" : {
"date" : "Tue Mar 06 15:08:41 GMT-04:00 2018",
"names" : "Anne"
}
}
My rules:
{
"rules": {
".read": "auth == null",
".write": "auth == null"
}
}
Should i use the Query function? Or something else?
Upvotes: 1
Views: 65
Reputation: 80934
Try this:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
Query q = ref.orderByChild("names").equalTo(Raamon);
q.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot datas: dataSnapshot.getChildren()){
String dates=datas.child("data").getValue().toString();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
using one specific value name
that is equal to Raamon
for example, you can then retrieve the date
that is related to it.
Upvotes: 1