I am trying to get the path of a queried document in Firebase Firestore. This is my code:
const location = await db.doc('/locations/US/regions/IOWA').get()
console.log(location.path)
However location.path
returns undefined.
location.id
works and returns the id.
I have used this as a resource: https://firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference#path
When you call get()
on a DocumentReference
, you get back a DocumentSnapshot
, which does not have a path
property.
You're probably looking for location.ref.path
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With