skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. First make a reference to the movies collection.
    Something like this (assuming you have access to your Firestore database):

    const moviesRef = collection(db, "movies");
    

    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 use getDocs 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:

    const subcol = collection(<document reference>, "subcollection name");
    

    From here you may use any way you need.

    For more info check Firebase docs

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search