I try to fetch data from Firestore with a whereGreaterThan
and whereArrayContains compound query. For some reason, this combination does not seem to work. If I omit one of the two statements they work and return almost the same data.
someCollection
?.whereGreaterThan("date", Date().startOfPreviousMonth)
?.whereArrayContains("ids", id)
?.get()
?.addOnSuccessListener { .... }
?.addOnFailureListener { .... }
In the documentation it is only stated that there are only these restrictions for compound queries:
Limitations
Note the following limitations for != queries:
- Only documents where the given field exists can match the query.
- You can't combine not-in and != in a compound query.
- In a compound query, range (<, <=, >, >=) and not equals (!=, not-in) comparisons must all filter on the same field.
For me, no one of these matches my problem. Any suggestions?
CodePudding user response:
There is no way you can use whereGreaterThan()
and whereArrayContains()
method calls in the same query without creating an index.
Create the corresponding index, either manually in the Firebase Console or automatically by clicking the link in the Android Studio logcat.
In Android, you can attach a Failure listener and get the URL from the error message.