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

Classic window functions first/last handle missing field incorrectly

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.1.1, 7.2.0-rc0, 6.0.12, 5.0.23, 7.0.4
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Minor Change
    • ALL
    • v7.1, v7.0, v6.0, v5.0
    • Hide

      Dataset

      db.missingData.find()
      [
        { _id: 1, item: 'cd', price: 7 },
        { _id: 2, item: 'cd', price: 5, quantity: 5 },
        { _id: 3, item: 'cd', price: 2 }
      ]

      Query : 

      db.missingData.aggregate([ { $setWindowFields: { partitionBy: "$item", sortBy: { price: 1 }, "output" : {"first" : {$first : "$quantity", window: { } } } } }])
      

       

      Results

      [
      { _id: 3, item: 'cd', price: 2 },
      { _id: 2, item: 'cd', price: 5, quantity: 5 },
      { _id: 1, item: 'cd', price: 7 }
      ]

       

       

      Expected Results

      [
      { _id: 3, item: 'cd', price: 2, first: null },
      { _id: 2, item: 'cd', price: 5, quantity: 5, first: null },
      { _id: 1, item: 'cd', price: 7, first: null }
      ]

       

      Show
      Dataset db.missingData.find() [   { _id: 1, item: 'cd' , price: 7 },   { _id: 2, item: 'cd' , price: 5, quantity: 5 },   { _id: 3, item: 'cd' , price: 2 } ] Query :  db.missingData.aggregate([ { $setWindowFields: { partitionBy: "$item" , sortBy: { price: 1 }, "output" : { "first" : {$first : "$quantity" , window: { } } } } }])   Results [ { _id: 3, item: 'cd' , price: 2 }, { _id: 2, item: 'cd' , price: 5, quantity: 5 }, { _id: 1, item: 'cd' , price: 7 } ]     Expected Results [ { _id: 3, item: 'cd' , price: 2, first: null }, { _id: 2, item: 'cd' , price: 5, quantity: 5, first: null }, { _id: 1, item: 'cd' , price: 7, first: null } ]  

      When the attribute tracked by first/last in the first/last document in the window has a missing attribute the functions return empty results. This is incorrect. According to the documentation they should return null to be consistent with the $group behaviour.

            Assignee:
            rui.liu@mongodb.com Rui Liu
            Reporter:
            foteini.alvanaki@mongodb.com Foteini Alvanaki
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: