0

I am using Flutter and Firebase Firestore and I want to query a collection group, but I only want the children of specific documents in Firestore.

I've tried querying all of the "parent" documents, then iterating over them checking for the conditions I'm looking for, and creating another Firestore query using that specific document ID, but this is very slow to do.

I have a collection called "Shops", and within "Shops" there is a field called "logoColour" and a sub-collection called "Customers". Each "Customers" document has several fields, but the one I'm interested in is "height"

What I want to do is create a query for the subcollection "Customer" where Customer[height] > 5", where Shops[logoColour] == "yellow"

The only similar post I could find is Firestore query subcollection and parent document which is dated 2021 and in Typescript

Is this possible in Flutter?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
oliver99
  • 3
  • 1

1 Answers1

0

Firestore can only filter on values in the documents that it returns.

So the only way to get the behavior you want with a single query is to replicate the value you want to filter on into each customer document.

If that's not acceptable, you'll indeed need to first query the parent documents and then load the subcollection docs for each - as you currently seem to be doing.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807