0
votes

I have an issue, I can't get subcollection from the document: I have firestore db with collection: collectionName Inside collection documents and inside one document subcollection "items"

  1. collectionName
    • Document1
      • Items <- subcollection
        • Item1
        • Item2

I use the following code but the items subcollection can't be retrieved from my db....`

```
QuerySnapshot snapshot = await Firestore.instance
      .collection('collectionName')
      .orderBy("order")
      .getDocuments();
```
`then`

```
snapshot.documents.forEach((document) {})
```

The document doesn't have the items subcollection

1

1 Answers

0
votes

You can not access a sub-collection like that. Last year, the team working at firestore released a new feature called the Collection Group. If you want to access the items collections try doing this:

Firestore.instance.collectionGroup('items')

This will contain all documents in the items sub-collection regardless of how deeply nested it is. Take a look at this for more information on collection groups.