Home > other >  Check If There Are Any Values in FireBase RealTime DataBase
Check If There Are Any Values in FireBase RealTime DataBase

Time:02-22

I have a firebase database that looks like this:

enter image description here

I want to check if a 'Data' Child Exists.

I have a start:

var check = firebase.database().ref().orderByKey().equalTo("data").once("value", function (snapshot) {
if (!snapshot.exists()) { 
    firebase.database().ref('data').set({
        messages: [],
        userIds: [],
        colours: [],
        names: [],
    });
}

});

I don't know what to put in the ref() function

CodePudding user response:

It's much simpler than what you're trying:

var check = firebase.database().ref("data");
check.once("value", function (snapshot) {
  if (!snapshot.exists()) { 
    ...
  }
});
  • Related