Reputation: 987
Hi all,
Im just wondering if it's possible to loop through children without knowing the parent node in Firebase. My structure right now is BOOKS/USERID/BOOKID I would love to loop through ALL the books without knowing the USERID or the parent. I'm hoping to do this from a Cloud Function. Is this possible?
Upvotes: 0
Views: 35
Reputation: 599176
If you want to loop over all books of all users in Node.js:
var rootRef = admin.database().ref("books");
return rootRef.once("value", function(booksSnapshot) {
booksSnapshot.forEach(function(userSnapshot) {
userSnapshot.forEach(function(bookSnapshot) {
console.log(bookSnapshot.key, bookSnapshot.val());
});
});
return true; // to flag that we're done
});
Upvotes: 1