Let's say we have a root collection named 'todos'.
Every document in this collection has:
title
: Stringtodo_items
Every document in the subcollection todo_items
has
title
: Stringcompleted
: BooleanI know that querying in Cloud Firestore is shallow by default, which is great, but is there a way to query the todos
and get results that include the subcollection todo_items
automatically?
In other words, how do I make the following query include the todo_items
subcollection?
db.collection('todos').onSnapshot((snapshot) => { snapshot.docChanges.forEach((change) => { // ... }); });
You can either go to Firestore Databases > Indexes console and do it, or use the firebase cli. But the easiest option is to just let your code (that performs the query) run and firestore will automatically error out when an index is missing.
I saw on the Firebase Firestore documentation that the limits for the "Maximum depth of subcollections" is 100.
A subcollection is a collection associated with a specific document. Note: You can query across subcollections with the same collection ID by using Collection Group Queries. You can create a subcollection called messages for every room document in your rooms collection: collections_bookmark rooms. class roomA.
To fetch orders subcollection we will need the documentId , so to get the documentId we need to fetch the users collection to get the userId . UserCard is a widget that displays the user details and on taping it new screen is pushed that contains all the orders of that particular user.
This type of query isn't supported, although it is something we may consider in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With