$project followed by $group gives incorrect results sometimes

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: 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
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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
            Reporter:
            Oleksandr Poliakov
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: