Handle OR filtering on empty query result with Firestore

Troubleshooting

I want to query a list of documents (called "activities") from Firestore. I have two conditions I want to filter this list with.

  1. "createdBy" field (type user reference) equals authenticated user reference

  2. "sharedGroups" field (list of "groups" document references) contains at least one groups document where the authenticated user reference is a group member (members field is a list of user references of the groups document)

So the relevant document structure is:

users:

  • reference

activities:

  • sharedGroups (List<DocRef(groups)>)

  • createdBy (DocRef(users))

groups:

  • members (List<DocRef(users)>)

What have you tried so far?

I was able to filter for the 1. condition.

I was also able to filter for the second condition by creating a second query where I query all groups documents where the members field contains the authenticated user reference and then using the result of that query to filter the sharedGroups field for that list with "groups Documents -> Reference mapping.

I was also able to combine both filters with an OR statement.

But if there are NO groups documents in my Firestore, I get an error (see screenshot). As soon as I create one groups document (even if its not matching the filter conditions at all, everything works fine.

My current query options for main query are:

Ignore Empty Filter Values -> true

Filter on Null Values -> false

Enable Infinite Scroll -> true

Listen for Changes -> true

Thank you for the help in advance.

Did you check FlutterFlow's Documentation for this topic?
Yes
2
6 replies