Is there a way I can get the name of the collection a Firestore document is stored in based off a variable of type
QueryDocumentSnapshot<DocumentData>? I’m using Firebase v9.
const snap = "" // The QueryDocumentSnapshot console.log("Collection name:", snap.ref.parent.id)
If that document is a part of sub-collection, then it’ll log name of that sub-collection. You can chain
.ref.parent again to get parent collection of the same.
Answered By – Dharmaraj
Answer Checked By – Jay B. (BugsFixing Admin)