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);
CodePudding user response:
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: