Reputation: 51
I want to get the pushed key by the help of its child value
Upvotes: 0
Views: 400
Reputation: 170
You can use this also
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
Query query = mDatabase.child("suppliersdata");
query.orderByChild("agencyname").equalTo("Babaji").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
Log.i("db", "onDataChange: Key : " + childSnapshot.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // never ignore errors
}
});
Upvotes: 0
Reputation: 599131
Say you have the agency name, then you can create a Firebase Database query to find the matching child nodes with that agency name:
DatabaseReference ref = FirebaseDatabase.getInstance();
Query query = ref.orderByChild("agencyname").equalTo("Babaji");
query.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
Log.d(TAG, "onChildAdded:" + dataSnapshot.getKey()+" "+ dataSnapshot.getChild("agencyname").getValue());
}
...
The onChildAdded
method above will be called for every node with agencyname
equal to Babaji
.
I recommend spending some more time in the Firebase documentation, specifically the sections on dealing with lists of data and on querying.
Upvotes: 1