Let's say we have a root collection named 'todos'.
Every document in this collection has:
title
: String- subcollection named
todo_items
Every document in the subcollection todo_items
has
title
: Stringcompleted
: 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) => {
// ...
});
});
I have faced the same issue but with IOS, any way if i get your question and if you use auto-ID for to-do collection document its will be easy if your store the document ID as afield with the title field in my case :
So when you retrieve lets say an array of to-do's and when click on any item you can navigate so easy by the path
I wish i could give you the exact code but i'm not familiar with Javascript
you could try something like this
Hope this helps !
If anyone is still interested in knowing how to do deep query in firestore, here's a version of cloud function getAllTodos that I've come up with, that returns all the 'todos' which has 'todo_items' subcollection.
This type of query isn't supported, although it is something we may consider in the future.