I have a collection inside a firestore called "movies" and there’s movies info. Inside them there are subcollections. How can I retrieve those subcollections containing episodes of my movies. There’s no docs in Firestore. Thanks
I have a collection inside a firestore called "movies" and there’s movies info. Inside them there are subcollections. How can I retrieve those subcollections containing episodes of my movies. There’s no docs in Firestore. Thanks
2
Answers
This can be done by FieldPath.documentId(). It can return a special sentinel
FieldPath
to refer to the ID of a document. It can be used in queries to sort or filter by the document ID. You may check this posted answer CollectionGroupQuery but limit search to subcollections under a particular document.First make a reference to the movies collection.
Something like this (assuming you have access to your Firestore database):
Then make a document reference to a document inside the movies collection. You can use the
doc()
function which takes in the db reference, the collection, and the target document id. If you don’t have the document id you can usegetDocs
to see all document ids in your collection. Finally once you have this document reference you can make a call to the sub collection which may look something like this:From here you may use any way you need.
For more info check Firebase docs