0

I have some documents with two arrays, one for the search functionality (keywords) and one to filter by services, using a single whereArrayContains or whereArrayContainsAny works perfectly. If I use them both together to get the documents both having the keywords for the search functionality and having at least one of the selected services it gets stuck in the loading state and never returns anything. For context I'm using jetpack compose with compose pager for the lazyColumn showing the documents.

This Works:

FirebaseFirestore.getInstance().collection("Clubs")
                .whereArrayContainsAny("services", sportsFilters)
                .get()
                .await()

This also Works:

FirebaseFirestore.getInstance().collection("Clubs")
                .whereArrayContains("keywords", searchString.lowercase().trim())
                .get()
                .await()

This is not Working:

FirebaseFirestore.getInstance().collection("Clubs")
                .whereArrayContains("keywords", searchString.lowercase().trim())
                .whereArrayContainsAny("services", sportsFilters)
                .get()
                .await()

1 Answer 1

1

From the Firestore documentation on query limitations:

You can use at most one array-contains clause per query. You can't combine array-contains with array-contains-any.

So the query you are trying to do is not possible on the Firestore API. The workaround is to perform one filter condition on the database, and then do the other filtering in your application code.

Sign up to request clarification or add additional context in comments.

1 Comment

Okay thanks for the acclaration. But by doing one of the filter conditions in the application wouldn't I be loosing the advantages of pagination? As I don't want to download all documents at once.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.