I am trying to update a value in my Firebase database. This is the structure of the database:
I need to update the value of status
to "accepted"
if the r_id
and s_id
have a specific value. The problem here is that the key for each friend_data
child is generated using "push" like this
db.child("friend_data").push().setValue(friend);
I have tried this question here and this one here but both don't meet my requirements. How do I go about solving this one?
Edit: I understand now that I am supposed to use a Query
here. This is what I tried:
final DatabaseReference db = FirebaseDatabase.getInstance().getReference("friend_data");
Query query = db.orderByChild("r_id").equalTo(f_id).orderByChild("s_id").equalTo(id);
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
db.child(child.getKey()).child("status").setValue("accepted");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
This does not work either because this error is raised
java.lang.IllegalArgumentException: You can't combine multiple orderBy calls!.
So how do I combine two Queries?