Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore get path of already queried document

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

like image 467
Leonard Niehaus Avatar asked Sep 03 '19 03:09

Leonard Niehaus


1 Answers

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.

like image 136
Frank van Puffelen Avatar answered Oct 04 '22 18:10

Frank van Puffelen