Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-72416

The find and findAndModify projection code does not honor the collection level collation

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 6.0.4, 6.2.0-rc5, 6.3.0-rc0
    • Affects Version/s: 4.4.18, 5.0.14, 6.0.3
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v6.2, v6.0, v5.0, v4.4
    • QE 2023-01-09
    • 3

      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.

            Assignee:
            arun.banala@mongodb.com Arun Banala
            Reporter:
            arun.banala@mongodb.com Arun Banala
            Votes:
            3 Vote for this issue
            Watchers:
            25 Start watching this issue

              Created:
              Updated:
              Resolved: