ISSUE DESCRIPTION AND AFFECTED VERSIONS
This bug impacts projections in find, findAndModify, and findOneAndDelete commands on collections with a specified collation.
When a collation on the collection level is specified, the find, findAndModify, and findOneAndDelete commands that use projection are affected by a bug that may cause MongoDB to crash after performing deletes without sending an acknowledgement to the user. This bug may also cause $sortArray in the projection to provide incorrect query results when sorting strings.
Find commands that use projection use the ExpressionContext object, which does not inherit collection level collation. All expressions used inside of the projection command will use the default collation, unless explicitly specified.
The find, findAndModify, findOneAndDelete commands are impacted when:
- The collection that is being queried against has collation specified,
- No explicit collation is provided in the query,
- It is using projection
Meeting all of the requirements above, if the query uses $elemMatch with positional projection ($ operator) it will cause a server crash. The findAndModify with {remove: true} and findOneAndDelete command may crash after issuing deletes without sending an acknowledgement to the user.
When the $sortArray is used in the projection, the find query will not use collection level collation, but will instead sort strings using a simple collation.
DIAGNOSIS AND AFFECTED VERSIONS
This bug affects all versions of MongoDB v4.4, v5.0, and v6.0.0-v6.0.3.
Nodes that hit this bug will crash with an invariant failure.
REMEDIATION AND WORKAROUNDS
Users may workaround this issue by specifying a collation field in their queries which matches the collection’s specified collation.
This issue is fixed in 6.0.4.
Original Description:
The find projection parsing code uses a very naive ExpressionContext object which does not inherit collection level collation. This means the expression evaluation code inside the projection spec does not use the collection level collation, leading to incorrect results.
- related to
-
SERVER-72450 $or with regex to $in rewrite depends on terms order
- Closed
-
SERVER-79592 [v4.4, v5.0] Avoid server crash when using positional projection with collation
- Closed