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

$project followed by $group gives incorrect results sometimes

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.0-rc0, 7.0.1, 6.0.10
    • Affects Version/s: 6.0.5
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • ALL
    • v7.0, v6.0
    • Hide
      Enterprise test> db.test.find()
      [
          { _id: 1, A: 2, B: 3 },
          { _id: 2, A: 2, B: 3 },
          { _id: 3, A: 4, B: 3 }
      ]
      Enterprise test> db.test.aggregate([{ $project : { A : "$A", B : "$B", _id : 0 } }, { $group : { _id : "$$ROOT" } }])
      [ 
          { _id: { A: 4, B: 3 } },
          { _id: { A: 2, B: 3 } }
      ]
      Enterprise test> db.test.aggregate([{ $project : { A : 1, B : 1, _id : 0 } }, { $group : { _id : "$$ROOT" } }])
      [
          { _id: { _id: 1, A: 2, B: 3 } },
          { _id: { _id: 2, A: 2, B: 3 } },
          { _id: { _id: 3, A: 4, B: 3 } }
      ]
      Enterprise test>
      
      Show
      Enterprise test> db.test.find() [ { _id: 1, A: 2, B: 3 }, { _id: 2, A: 2, B: 3 }, { _id: 3, A: 4, B: 3 } ] Enterprise test> db.test.aggregate([{ $project : { A : "$A" , B : "$B" , _id : 0 } }, { $group : { _id : "$$ROOT" } }]) [ { _id: { A: 4, B: 3 } }, { _id: { A: 2, B: 3 } } ] Enterprise test> db.test.aggregate([{ $project : { A : 1, B : 1, _id : 0 } }, { $group : { _id : "$$ROOT" } }]) [ { _id: { _id: 1, A: 2, B: 3 } }, { _id: { _id: 2, A: 2, B: 3 } }, { _id: { _id: 3, A: 4, B: 3 } } ] Enterprise test>
    • QO 2023-06-12, QE 2023-07-24

      See steps to reproduce.

      In the steps below we expected both aggregation pipelines return the same results. In server version before v6 it was working as expected. The problem seems to started with v6 (we tested 6.0.2 and 6.0.5 versions).

      The difference between two aggregation pipelines is that in the first case we project using A : "$A" and in the second we project using A : 1. We expect them to be equivalent.

            Assignee:
            rui.liu@mongodb.com Rui Liu
            Reporter:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: