Search code examples
androidfirebasekotlingoogle-cloud-firestorelogical-and

Get documents by tags


I've been using Firestore to build an Android app and I run into the next limitation that I have no idea to deal with it.

I need to retrieve documents by tags that are stored in an array-field. However, there can be only one whereArrayContains per query. How am I supposed to get documents by more than one tag?

Can you think of any clever solution to that?


Solution

  • You can only have one whereArrayContainsAny condition on a query, but you can have up to 10 whereArrayContains conditions.

    From the documentation on query limitations:

    • Cloud Firestore provides limited support for logical OR queries. The in and array-contains-any operators support a logical OR of up to 10 equality (==) or array-contains conditions on a single field. For other cases, create a separate query for each OR condition and merge the query results in your app.
    • You can use only one in or array-contains-any clause per query. You can't use both in and array-contains-any in the same query.