`SORT_MERGE` stage merges multiple sorted streams.
When the collection has collation enabled, the comparison function has three different cases:
- If for both left-hand-side and right-hand-side the sort attribute are present in the index key, then a regular BSONObj comparison is enough, as both index-keys are collation-encoded
- If none of them have sort attribute as part of the index key, perform the comparison with the help of the collator
- If only of the sides has sort attribute as part of the index key, then perform the collation-encoding of the other side and then perform the regular BSONObj comparison with both sides being collation-encoded
The issue arises in the third case, when we are trying to perform the collation-encoding of a document with a missing sort attribute. In this case an invariant is violated and mongod crashes.
The solution would be to perform the collation-encoding only in the case, when the sort attribute is present.