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()
CodePudding user response:
From the Firestore documentation on query limitations:
You can use at most one
array-contains
clause per query. You can't combinearray-contains
witharray-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.