How can I check if the name exists in the users database?
With this code I can see that the user exists but when the variable user
changes to another user I do not get any error.
var user = 'Moises';
firebase.database().ref('usuarios').orderByChild('usuario').equalTo(user).on('child_added', function(data) {
console.log('user exist');
}, function(error) {
console.log(error);
});
@Marcos Solution:
firebase.database().ref('usuarios').orderByChild('usuario').equalTo(user).once('value').then(function(snapshot) {
console.log(snapshot.exists() ? 'user exist' : 'user non existent');
});