I have the following dataset:
person-base
{
-K771quXhYWTo-F8oei9
{
person: "Sam"
value: 2
}
-K771uFngeQ6j0rvDhN_
{
person: "Joe"
value: 1
}
}
I am trying to get the value of one of these keys based on this person. I created a query that I use to indicate the value of a person that matches the value of my variable personName (in this case, “Sam”), and still, based on what I see in the console, it correctly extracts the corresponding key and this children.
My code is:
var personRef = new Firebase("https://person-base.firebaseio.com/");
var personName = "Sam";
var query = personRef.orderByChild('person').equalTo(personName);
query.on('value', function(snapshot) {
console.log(snapshot.val());
console.log(snapshot.val().key());
});
My plan was to get the parent key (generated using .push) that contains the value of my face, and then run something like the code that I have below to get the value
personRef.child(key).on('value', function(childSnapshot) {
var obj = childSnapshot.val();
console.log(obj.value);
});
However, I cannot get the parent with my request.
My fiddle for more reference: https://jsfiddle.net/y20Lucyx/1/