GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
1.17k stars 155 forks source link

Query with array contains requires unexpected index creation #498

Open zacsst opened 6 months ago

zacsst commented 6 months ago

Hello

Thanks for the great library. I'm in the middle of switching from swift to KMP using firestore database. Using version 1.12

The following query that I am migrating is requiring an unexpected index. I did not expect to need a new index as I ran the same query in swift. The query works, but can someone help me understand why this is?

Any insight into why this is being required?

This is the query

feedCollection .where { USERS contains userId } .orderBy(field = LAST_POST_TIME, direction = Direction.DESCENDING) .get() .documents

The index required

image

For reference: this is my query in swift code

Firestore.firestore().collection(FeedConstants.COLLECTION) .whereField(FeedConstants.USERS, arrayContains: user.id) .order(by: FeedConstants.LAST_POST_TIME, descending: true) .getDocuments{ (querySnapshot, error) in