kofifus kofifus - 5 months ago 30
Javascript Question

how to get firebase.database.Reference full path

consider

var adaRef = firebase.database().ref("users/ada");


How can I get the full path of ref ? that is "users/ada" ?

Answer

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. One way of doing that both:

adaRef.toString().substring(firebase.database.ref().toString().length-1)

and

adaRef.toString().substring(adaRef.root.toString().length-1)

Will both print /users/ada

Comments