I just want to check if the data I'm about to insert allready exists on my Firebase, and if so I just want to break the add function:
FBDB.addCampain=function (campain){
CampiansRef.once('value',function(snapshot){
snapshot.forEach(function(childSnapshot){
if(campain.Name==childSnapshot.val().Name){
console.log("campain allredy exists on the DB");
return false; //I want to break the addCampain function from here!
}
});
});
var newCampainRef = CampiansRef.push();
campain.id = newCampainRef.key();
newCampainRef.set(campain,function(error){
if(error){
console.log("an error occured the campain did not add to the DB, error:" ,+error);
return false;
}
else{
console.log("campain succssesfuly added to the DB");
return true;
}
});
};
What currently happens is that even if the campaign exists on the database it still continues to the actual adding code. There must be a way to "break" the addCampain
function within an anonymous function inside it, or even pass the "return false" up to the main scope.