I am making an Android application using Firebase
realtime database. When a new user registers on my app, that user\'s data is saved in the Firebase database. <
Try this:
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("Users");
ref.orderByChild("username").equalTo(Nick123).addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
if(dataSnapshot.exist() {
//username exist
}
}
You have to use orderbychild
and equalto
to check the value if it is there.
If you dont use orderbychild
and equalto
then it will just check if username
child node is there and doesnt care about the value.
this orderByChild("username").equalTo(Nick123)
is like saying:
WHERE username=Nick123