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

XMLWordPrintableJSON

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

      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
            Reporter:
            Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: