Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud Firestore deep get with subcollection

Let's say we have a root collection named 'todos'.

Every document in this collection has:

  1. title: String
  2. subcollection named todo_items

Every document in the subcollection todo_items has

  1. title: String
  2. completed: Boolean

I 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) => {     // ...   }); }); 
like image 967
qeroqazo Avatar asked Oct 06 '17 17:10

qeroqazo


People also ask

How do I get data from Subcollection firestore?

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.

What is the limited depth of Subcollection in firestore?

I saw on the Firebase Firestore documentation that the limits for the "Maximum depth of subcollections" is 100.

What is a Subcollection firestore?

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.

How do you get Subcollection in firestore in flutter?

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.


1 Answers

This type of query isn't supported, although it is something we may consider in the future.

like image 79
Dan McGrath Avatar answered Sep 20 '22 13:09

Dan McGrath