I have the following JSON structure in my Firebase Database:
- users
|
+--- key: 123
| |
| +-----name : Tom
| +-----email: tom@mymail.com
|
+--- key: 456
|
+-----name : Peter
+-----email: peter@othermail.com
Now I want to check if any user with the email tom@mymail.com
exists or not.
I thought:
DatabaseReference usersRef = db.getReference("users");
usersRef.orderByChild("email")
.equalTo("tom@mymail.com")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//fires if exists
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
But this only fires if a user exists and not if it doesn't. How to do it properly?