Reputation: 222
I am making a collection group query and getting the data by .get method , is there any way to get the document id which consists that collection ?
Collection:Users ------ Doccument:user1 -> Collection:Posts -> Document:post 1,2,3.. ------- Doccument:user2 -> Collection: Posts -> Document:post a,b,c..
So while making the query i am getting post 1,2,3.. & a,b,c..
But how to get the document document id from where a,b,c or 1,2,3 are comming ?
In this case it i want to get user 1 & user 2 as result !
Just let me know if it is possible first !
Upvotes: 0
Views: 171
Reputation: 83103
For a document of any of the Posts
subcollections you need to:
CollectionReference
of the Document's parent Collection, with the getParent()
method of the DocumentReference
CollectionReference
, call the getParent()
method which returns the DocumentReference
of the Collection's parent Document.getId()
method on this DocumentReference
. You're done.Upvotes: 1