Firebase Firestore – Access document within another document of unknown id

You can use a collection group query, as detailed in the docs, it allows accessing subcollections with a specific name from every documents at once:

db.collectionGroup('PROMOTIONS').get().then(snapshot => {
  snapshot.forEach(doc => {
    console.log("this is your promotion", doc)
   }
});

Note that you will need to set an index as well a an appropriate security rule for Firestore:

match /{path=**}/PROMOTIONS/{id} {
  allow read: if true;
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top