Is there a method in firebase, which can check if value exist in DB? Firebase has method .exists(), but according to docs it checks only the keys.
I have the followi
I can't make comments yet, so I'm posting an answer:
To add to the suggested answer, if you wanted to query whether or not any users exist, you can try to improve performance by adding .limitToFirst(1) or .limitToLast(1). This way you can limit your retrieved data to the minimum:
//Check if any users exist
firebase.database().ref(`users`).limitToFirst(1).once("value", snapshot => {
if (snapshot.exists()){
console.log("exists!");
// TODO: Handle that users do exist
return true;
}
// TODO: Handle that users do not exist
});
sources: https://firebase.google.com/docs/reference/js/firebase.database.Query#limitToFirst