I'm still pretty new to Firebase and still learning how to do "simple" things with it. I have a structure that looks like this:
"users": {
"-KY5FJBudXmKv07noYbZ": {
"emailAddress" : "a@a.com",
"tags": {
"red": "8dfhj34sd983ie",
"green": "9f5d6g8er2d"
}
},
"-KY5JM-NGjNgUXwrBRhs": {
"emailAddress": "b@b.com",
"tags": {
"blue": "58ewgsg656fd",
"pink": "sdf6g3dg5e6d"
}
},
"-K_0c7wslBiOceF30R-5": {
"emailAddress": "c@c.com",
"tags": {
"blue": "58ewgsg656fd",
"brown": "xx4f5g68d5d1",
"black": "8941gs8536sdf1"
}
},
}
What I want to do is fetch the nodes within users
that contain a child in its tags
where that value is 58ewgsg656fd
.
In this example, that would be the "blue": "58ewgsg656fd"
child and the users
nodes that contain them are last two (...0R-5
and ...BRhs
) one in that structure.
This is what I have so far:
DatabaseReference usersRef = database.getReference("users");
usersRef.orderByChild("tags").[NOT SURE WHAT GOES HERE].addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getChildrenCount() == 0) {
// No users found with that tag
} else {
// Users found with that tag
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Error occurred
}
});
What code should I write to fetch those nodes?