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

Disallow dotted full-path renames for '$elemMatch' expressions

    • Query Execution
    • Fully Compatible
    • ALL
    • v8.0, v7.3, v7.0
    • QE 2024-05-27, QE 2024-06-10, QE 2024-06-24
    • 0

       The following pipeline returns different results with optimisations disabled via the "disablePipelineOptimization" failpoint:

      // Collection contains only the document: {outer: [{inner: 0}]}
      [
          {
              $project: {
                  flattened: {
                      $map: {input: '$outer', as: "iter", in : "$$iter.inner"},
                  },
              },
          },
          {
              $match: {flattened: {$elemMatch: {$eq: 0}},
          }
      ]; 
      • With the optimisation it returns []
      • Without the optimisation it returns [{flattened: [0]}]

      The rewrite turns the match expression into {$match: {"outer.inner": {$elemMatch: {$eq: 0}}}} which is not exactly the same in this context due to implicit dotted array traversal. [Mongo docs.

            Assignee:
            catalin.sumanaru@mongodb.com Catalin Sumanaru
            Reporter:
            catalin.sumanaru@mongodb.com Catalin Sumanaru
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: