I would like test if a data exist in Firebase before to add it. But I have a problem with my method: I try to list all data with this Javascript code:
var theDataToAdd = userName;
var usersRef = new Firebase('https://SampleChat.firebaseIO-demo.com/users/');
usersRef.on('child_added', function(snapshot) {
var message = snapshot.val();
if (message.name == theDataToAdd)
alert ("exist");
});
But if the user doesn't exist, it will be added before, then my code says that he exists. You will say that is normal because my alert is called only when "child_added", but I don't see how do.
I have also try with the "value" event but my "message.name" is empty.
How can I fix it?