Firestore - get the parent document of a subcollection
The QuerySnapshot
points to a number of QueryDocumentSnapshot
instances.
From a QueryDocumentSnapshot
, you can get the collection it's from with:
snapshot.getRef().getParent()
And then the parent DocumentReference
is:
snapshot.getRef().getParent().getParent()
So to get a subscollection of the parent document with:
snapshot.getRef().getParent().getParent().collection("name_of_subcollection")
Yes, I agree... that could've been a bit more readable. :)