I am trying to get the first child of a firebase object. My ref looks like this:
var sitesToVisitRef = firebase.database().ref('sitesToVisit')
I know the ref works because I can write to it. My data structure can look like this:
sitesToVisit:
arstechnica-com:
url: "https://arstechnica.com"
However, I don't know the key (arstechnica-com), but I need to get the url.
I am trying to with this code:
var nextUrl;
sitesToVisitRef.limitToFirst(1).once('value', function(snapshot) {
console.log("snapshot key" + snapshot.key);
console.log("snapshot.val.url = " + snapshot.val().url);
console.log("snapshot.val" + snapshot.val());
nextUrl = snapshot.val().url;
}
});
But snapshot.key logs as "sitesToVisit", not "arstechnica-com".
Any help would be greatly appreciated. Thank you so much!