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

Distinct scan in aggregation doesn't fetch document when group uses $$ROOT

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 4.1.10
    • Affects Version/s: 4.1.8
    • Component/s: Aggregation Framework
    • None
    • Fully Compatible
    • ALL
    • Hide

       

      Show
       
    • Query 2019-03-25, Query 2019-04-08

      Looks like DISTINCT_SCAN added in SERVER-9507 doesn't request the full document like it does correctly individual fields.

      // correct
      db.newTest.aggregate([
         {$sort:{valueDate:1}},
         {$group:{_id: "$valueDate", first: {$first: "$farmId"}}}
      ])
      { "_id" : ISODate("2019-01-01T00:00:00Z"), "first" : 3 }
      { "_id" : ISODate("2019-02-01T00:00:00Z"), "first" : 1 }
      //incorrect
      db.newTest.aggregate([
         {$sort:{valueDate:1}},
         {$group:{_id: "$valueDate", first: {$first: "$$ROOT"}}}
      ])
      { "_id" : ISODate("2019-01-01T00:00:00Z"), "first" : { "valueDate" : ISODate("2019-01-01T00:00:00Z") } }
      { "_id" : ISODate("2019-02-01T00:00:00Z"), "first" : { "valueDate" : ISODate("2019-02-01T00:00:00Z") } }
       

            Assignee:
            justin.seyster@mongodb.com Justin Seyster
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: