Firestore 获取已查询文档的路径

Leo*_*aus 5 javascript node.js firebase google-cloud-firestore

我正在尝试获取 Firebase Firestore 中查询文档的路径。这是我的代码:

const location = await db.doc('/locations/US/regions/IOWA').get()
console.log(location.path)
Run Code Online (Sandbox Code Playgroud)

但是location.path返回未定义。

location.id 工作并返回ID。

我已将此用作资源:https : //firebase.google.com/docs/reference/js/firebase.firestore.DocumentReference#path

Fra*_*len 6

当您调用get()a 时DocumentReference,您会返回 a DocumentSnapshot,它没有path属性。

您可能正在寻找location.ref.path.