consider
var adaRef = firebase.database().ref(\"users/ada\");
How can I get the full path of ref ? that is \"users/ada\" ?
That's surprisingly simple:
adaRef.toString()
Will print the full URL: https://<your-app>firebaseio.com/users/ada
So to just get the path, you substring it out of there. Two ways of doing that are:
adaRef.toString().substring(firebase.database().ref().toString().length-1)
or:
adaRef.toString().substring(adaRef.root.toString().length-1)
both will print /users/ada
On new versions of the framework you could use:
snapshot.ref.path.toString()
being snapshot
the result of a call on a Database Reference
.
Maybe this can be helpful.
Following on Frank's answer I extended firebase as follows:
firebase.database.Reference.prototype.fullkey = function() {
return this.toString().substring(this.root.toString().length-1);
}
then you can do
adaRef.fullkey() // returns /users/ada
(I would like to call this 'path' but that seems to be reserved by FB)