You have a hybrid structure, which complicates things. But if you are just looking for a match under /users/-K....
, you can find the match with something like:
Query query = ref.child("users").orderByChild("User/username").equalTo("fofof");
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot userSnapshot: dataSnapshot.getChildren()) {
Log.i(TAG, "fofof exists and is stored under key "+userSnapshot.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
}
});
A few warnings about your current set-up though:
- you're storing users under a push ID. While push IDs are great for collections that don't have a natural key and that you want to store chronologically, it is better to store your users under the UID. So e.g.
/users/s5iu...
.
- you've nested the user information one level deeper than is necessary. While this works, I'd get rid of the
User
level in your tree.
- you have a user directly under
/users
, while others are stored one level deeper. Creating such a hybrid model is a bad idea.