I want to check if the specific user is present in database or not and if it is present then I don't want to override the data in the database. I am using unique key generation at every node provided by firebase as User Id's
So I don't want to duplicate the user if he is already present.
How can I check if this user is present in database without listening to any events because my program execution is dependent on this values
When I am doing this the execution goes in a infinite loop
USER_REFERENCE.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot d : children) {
if (d.child("email").exists()) {
if (d.child("email").getValue().equals(user.getEmail())) {
user.setUserId(d.getKey());
mPresenter.saveUserIntoSession(user);
} else {
String userId = addUser(user);
user.setUserId(userId);
mPresenter.saveUserIntoSession(user);
}
}
}
}