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

$or to $in conversion flawed

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 5.0.10, 6.0.0-rc9, 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v6.0, v5.0
    • QO 2022-05-30, QO 2022-06-13
    • 17

      We have come across a problem that was introduced with this change: SERVER-34012. The exact line causing this is https://github.com/mongodb/mongo/blame/master/src/mongo/db/matcher/expression_tree.cpp#L250.

      This problem can only be seen on MongoDB v5, earlier versions work properly.

      Steps to reproduce:

      Create "some" collection and then run:

      db.getCollection("some").aggregate({$match: { "$or" : [ { "x" : "a" }, { "x" : "b" }, { "x" : /c/ }] } })
      

      Expected output: No failure.
      Output:

      uncaught exception: Error: command failed: {
              "ok" : 0,
              "errmsg" : "Failed to optimize pipeline :: caused by :: Failed to optimize expression :: caused by :: Incorrect number of non-equivalent expressions",
              "code" : 3401204,
              "codeName" : "Location3401204"
      } with original command request: {
              "aggregate" : "FileNodeVersions",
              "pipeline" : [
                      {
                              "$match" : {
                                      "$or" : [
                                              {
                                                      "x" : "a"
                                              },
                                              {
                                                      "x" : "b"
                                              },
                                              {
                                                      "x" : /c/
                                              }
                                      ]
                              }
                      }
              ],
              "cursor" : {
      
              },
              "lsid" : {
                      "id" : UUID("af1c7696-912f-4ad8-a53b-8eb9db5c0162")
              }
      

            Assignee:
            timour.katchaounov@mongodb.com Timour Katchaounov
            Reporter:
            daniel.hegener@gmx.net Daniel Hegener
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: