Skip to content

Instantly share code, notes, and snippets.

@anantn
Last active April 14, 2021 15:29
Show Gist options
  • Save anantn/4964365 to your computer and use it in GitHub Desktop.
Save anantn/4964365 to your computer and use it in GitHub Desktop.
Firebase: Get the parent of a snapshot.
function getParent(snapshot) {
// You can get the reference (A Firebase object) from a snapshot
// using .ref().
var ref = snapshot.ref();
// Now simply find the parent and return the name.
return ref.parent().name();
}
var testRef = new Firebase("https://example.firebaseIO-demo.com/foo/bar");
testRef.once("value", function(snapshot) {
// Should alert "Name of the parent: foo".
alert("Name of the parent: " + getParent(snapshot));
});
@lohwa
Copy link

lohwa commented Apr 5, 2019

thank you in advance

@RameshMathad
Copy link

how to retrieve parent using a collection of children firestore web app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment