When we use an index to provide a sort, but the filter does not require that the index respect the query's collation, we fail to check that the index respects the query's collation.
Without an index, we respect the collation (strength: 2 indicates case-insensitivity):
> db.coll.find({}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2}) { "a" : "a" } { "a" : "A" } { "a" : "b" } { "a" : "B" }
With an index, we do not respect the collation:
> db.coll.ensureIndex({a: 1}) > db.coll.find({}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2}) { "a" : "A" } { "a" : "B" } { "a" : "a" } { "a" : "b" }
An example where the filter doesn't require the index respect the query's collation:
> db.coll.find({a: {$exists: true}}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2}); { "a" : "a" } { "a" : "A" } { "a" : "b" } { "a" : "B" } > db.coll.ensureIndex({a:1}) > db.coll.find({a: {$exists: true}}, {_id: 0}).sort({a: 1}).collation({locale:"en_US",strength:2}) { "a" : "A" } { "a" : "B" } { "a" : "a" } { "a" : "b" }
Another example where the filter doesn't require the index respect the query's collation:
> db.coll.find({a: {$gt: {b: 5}}}, {_id: 0}).sort({a: 1}).collation({locale:"en_US", strength: 2}) { "a" : { "b" : "A" } } { "a" : { "b" : "a" } } { "a" : { "b" : "B" } } { "a" : { "b" : "b" } } > db.coll.ensureIndex({a: 1}) > db.coll.find({a: {$gt: {b: 5}}}, {_id: 0}).sort({a: 1}).collation({locale: "en_US", strength: 2}) { "a" : { "b" : "A" } } { "a" : { "b" : "B" } } { "a" : { "b" : "a" } } { "a" : { "b" : "b" } }