Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firestore: query for doc subcollection size

I have Project docs that have Items subcollections. Now I want to fetch all projects that have at least one item in their subcollection. Is that possible?

Something like:

getDocs(collection(getDB(), "Projects"), where("Items.size",">",0);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is not possible with Firestore. What you should do instead is maintain a separate integer field in the document that tracks the size of the Items subcollection so that you can query it separately. You will need to make sure that any changes to the Items subcollection result in changes to that new field that tracks its size.

See also:

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading