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

issues with GROUP_BY stage in aggregation (6.2.0)

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization
    • ALL
    • Hide

      example data:

       

      [
      { metadata: { testId: "foo", publicFacetLabels: {difficulty: "easy"}, score: 2 } },
      { metadata: { testId: "foo", publicFacetLabels: {difficulty: "easy"}, score: 2 } },
      { metadata: { testId: "foo", publicFacetLabels: {difficulty: "easy"}, score: 2 } },
      { metadata: { testId: "foo", publicFacetLabels: {difficulty: "hard"}, score: 2 } },
      { metadata: { testId: "foo", publicFacetLabels: {difficulty: "hard"}, score: 2 } },
      ]
      

      Execute pipeline:

      [{
       $match: {
        'metadata.testId': 'foo'
       }
      }, {
       $group: {
        _id: {
         difficulty: '$metadata.publicFacetLabels.difficulty'
        },
        responseCount: {
       $count: {}
        },
        sumScore: {
         $sum: '$metadata.score'
        }
       }
      }, {
       $project: {
        _id: 0,
        sumScore: 1,
        responseCount: 1,
        difficulty: '$_id.difficulty'
       }
      }] 

      Expected Result:

      [
      {difficulty: "easy", sumScore: 6, responseCount: 3},
      {difficulty: "hard", sumScore: 4, responseCount: 2}
      ]

       

      Show
      example data:   [ { metadata: { testId: "foo" , publicFacetLabels: {difficulty: "easy" }, score: 2 } }, { metadata: { testId: "foo" , publicFacetLabels: {difficulty: "easy" }, score: 2 } }, { metadata: { testId: "foo" , publicFacetLabels: {difficulty: "easy" }, score: 2 } }, { metadata: { testId: "foo" , publicFacetLabels: {difficulty: "hard" }, score: 2 } }, { metadata: { testId: "foo" , publicFacetLabels: {difficulty: "hard" }, score: 2 } }, ] Execute pipeline: [{  $match: {   'metadata.testId' : 'foo'  } }, {  $group: {   _id: {    difficulty: '$metadata.publicFacetLabels.difficulty'   },   responseCount: {  $count: {}   },   sumScore: {    $sum: '$metadata.score'   }  } }, {  $project: {   _id: 0,   sumScore: 1,   responseCount: 1,   difficulty: '$_id.difficulty'  } }] Expected Result: [ {difficulty: "easy" , sumScore: 6, responseCount: 3}, {difficulty: "hard" , sumScore: 4, responseCount: 2} ]  
    • QO 2023-04-03

      I have pipelines that previously worked but no longer do since upgrading to 6.2.0. They all specifically have a GROUP_BY stage that is no longer working as expected. e.g.

      [{
       $match: {
        'metadata.testId': 'foo'
       }
      }, {
       $group: {
        _id: {
         difficulty: '$metadata.publicFacetLabels.difficulty'
        },
        responseCount: {
         $count: {}
        },
        sumScore: {
         $sum: '$metadata.score'
        }
       }
      }, {
       $project: {
        _id: 0,
        sumScore: 1,
        responseCount: 1,
        difficulty: '$_id.difficulty'
       }
      }]

      In the above example I was previously getting the following result

       

      {
       responseCount:166,       
       sumScore: 150,
       difficulty: "Hard"
      } 

      Since updating to version 6.2.0 I am getting:

       

      {
      sumScore: 150,
      } 
      

      Note: these pipelines are being run against a timeseries collection

       
       

            Assignee:
            milena.ivanova@mongodb.com Milena Ivanova
            Reporter:
            john@synap.ac John Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: