Gabriel Gabriel - 1 year ago 133
Javascript Question

Check if value exists in firebase DB

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 keys. I have the following structure:

"users": {
"fName": "Peter",
"ID": "U1EL9SSUQ",
"username": "peter01"
"fName": "John",
"ID": "U1EL5623",
"username": "john.doe"

I want to check if ID with value


There is no explicit exists() method but you can work with the following logic to handle it.

ref.child("users").orderByChild("ID").equalTo("U1EL5623").once("value", function(snapshot) {
    var userData = snapshot.val();
    if (userData){