[SERVER-72416] The find and findAndModify projection code does not honor the collection level collation Created: 28/Dec/22  Updated: 29/Oct/23  Resolved: 06/Jan/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.4.18, 5.0.14, 6.0.3
Fix Version/s: 6.0.4, 6.2.0-rc5, 6.3.0-rc0

Type: Bug Priority: Critical - P2
Reporter: Arun Banala Assignee: Arun Banala
Resolution: Fixed Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
Related
related to SERVER-72450 $or with regex to $in rewrite depends... Closed
related to SERVER-79592 [v4.4, v5.0] Avoid server crash when ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.2, v6.0, v5.0, v4.4
Sprint: QE 2023-01-09
Participants:
Case:
Linked BF Score: 3

 Description   
Issue Status as of May 16, 2023

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:

  1. The collection that is being queried against has collation specified,
  2. No explicit collation is provided in the query,
  3. 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.



 Comments   
Comment by Githook User [ 23/Jan/23 ]

Author:

{'name': 'Arun Banala', 'email': 'arun.banala@mongodb.com', 'username': 'banarun'}

Message: Revert "SERVER-72416 Find and findAndModify commands' ExpressionContext should inherit collection level collation"

This reverts commit aed1cb6469f207e7e6ab053fdfb2c472b7b345ec.
Branch: v5.0
https://github.com/mongodb/mongo/commit/9642e21ac80ca1b1b019b56a57b21b487107ad3f

Comment by Githook User [ 06/Jan/23 ]

Author:

{'name': 'Arun Banala', 'email': 'arun.banala@mongodb.com', 'username': 'banarun'}

Message: SERVER-72416 Find and findAndModify commands' ExpressionContext should inherit collection level collation

(cherry picked from commit 8fb9a8b130995a379fa1943233e9b91816cebd34)
(cherry picked from commit 48bce2f356dd7f1ba789fd0a8b965299041bec56)
Branch: v5.0
https://github.com/mongodb/mongo/commit/a836a299e8237824cdedc45080de97274a3fda40

Comment by James Hippler (Inactive) [ 06/Jan/23 ]

arun.banala@mongodb.com

We're scheduled to release 6.0.4-rc0 on Tuesday, January 10th.  I'm going through any outstanding items in the 6.0 Release Board for status updates.

  • Can this SERVER ticket be closed?  It looks like the changes have been merged into the master branch.
Comment by Githook User [ 05/Jan/23 ]

Author:

{'name': 'Arun Banala', 'email': 'arun.banala@mongodb.com', 'username': 'banarun'}

Message: SERVER-72416 Find and findAndModify commands' ExpressionContext should inherit collection level collation

(cherry picked from commit 2f1b039897aa55eb3007abbe1020e6e4967b4140)
Branch: v6.2
https://github.com/mongodb/mongo/commit/eb8910b86a503d0756371a9f69af3baf5ebd2044

Comment by Githook User [ 05/Jan/23 ]

Author:

{'name': 'Arun Banala', 'email': 'arun.banala@mongodb.com', 'username': 'banarun'}

Message: SERVER-72416 Find and findAndModify commands' ExpressionContext should inherit collection level collation

(cherry picked from commit 8fb9a8b130995a379fa1943233e9b91816cebd34)
Branch: v6.0
https://github.com/mongodb/mongo/commit/34c3c8eb005f58da7bf733639eab49251206bd53

Comment by Githook User [ 05/Jan/23 ]

Author:

{'name': 'Arun Banala', 'email': 'arun.banala@mongodb.com', 'username': 'banarun'}

Message: SERVER-72416 Find and findAndModify commands' ExpressionContext should inherit collection level collation
Branch: master
https://github.com/mongodb/mongo/commit/2f1b039897aa55eb3007abbe1020e6e4967b4140

Generated at Thu Feb 08 06:21:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.