Getting Node Names From Firebase Database Based On Emailid Match
Solution 1:
To get the key of the childSnapshot call childSnapshot.key
:
.then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
childKey = childSnapshot.key; // Get the key of the child
childData = childSnapshot.val();
name = childData.Name;
var n = login.localeCompare(name);
console.log(name);
if (n != 0) {
var eid = snapshot.val();
console.log("Hello" + eid);
}
console.log(snapshot.val());
})
})
Solution 2:
There is now a shallow command in the REST API that will fetch just the keys for a path. This has not been added to the SDKs yet.
In Firebase, you can't obtain a list of node names without retrieving the data underneath. Not yet anyways. The performance problems can be addressed with normalization.
Essentially, your goal is to split data into consumable chunks. Store your list of video keys, possible with a couple meta fields like title, etc, in one path, and store the bulk content somewhere else. For '/video_meta/id/link, title, ... /video_lines/id/...'
To learn more about denormalizing, check out this article: https://www.firebase.com/blog/2013-04-12-denormalizing-is-normal.htm
To get the "name" of any snapshot (in this case, the ID created by push()
) just call name()
like this:
var name = snapshot.name();
If you want to get the name that has been auto-generated by push()
, you can just call name()
on the returned reference, like so:
var newRef = myDataRef.push(...);
var newID = newRef.name();
Post a Comment for "Getting Node Names From Firebase Database Based On Emailid Match"