I have a firebase database that looks like this:
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()) {
...
}
});