consider this data structure referenced on the Firebase quick start guide (here)
{name: {first: Fred,last: Flintstone}
The docs say that one can access the datasnapshot location of each child object of name returned from a query using:
var ref = new Firebase(https://docs-examples.firebaseio.com/samplechat/users/fred);
ref.once(value, function(snapshot) {
var nameSnapshot = snapshot.child(name);
var name = nameSnapshot.val();
name === { first: Fred, last: Flintstone}
var firstNameSnapshot = snapshot.child(name/first);
var firstName = firstNameSnapshot.val();
firstName === Fred
var lastNameSnapshot = snapshot.child(name).child(last);
var lastName = lastNameSnapshot.val();
lastName === Flintstone
var ageSnapshot = snapshot.child(age);
var age = ageSnapshot.val();
age === null (because there is no age child in the data snapshot)
});
But what's a little weird about this is when the following lines are processed.
var nameSnapshot = snapshot.child(name);
var name = nameSnapshot.val();
name.first, and name.last are also retrieved. So why would one use this snapshot method child()? Or rather when would it be beneficial to use this method, since when you pull the parent object, Firebase pulls all children, or is there a way to retrieve a parent node/object without pulling some of it's children? Then this method to me would make sense.
Any information would be gratefully appreciated! Thanks