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

$densify causes duplicate documents when unit = months

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration

      The issue only happened with unit months in the generated test but this could be a coincidence. The start and end dates required to reproduce are finicky.

      Repro:

      // Setup
      db.a.drop()
      db.a.aggregate([ { "$densify" : { "field" : "obj.obj.obj.date", "range" : { "step" : 9, "unit" : "month", "bounds" : [ ISODate("2019-01-31T21:53:45.323Z"), ISODate("2020-06-02T10:40:15.842Z") ] } } }, { "$sort" : { "obj.obj.obj.date" : 1, "_id" : 1 } }, { "$limit" : 1000 } ])
      // Result:
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-01-31T21:53:45.323Z") } } } }
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-10-31T21:53:45.323Z") } } } }
      // -----
      // Adding a document in the range produces additional documents at the start of the densify range
      db.a.insert({obj: {obj: {obj: {date: new Date("2019-10-01")}}}})
      db.a.aggregate([ { "$densify" : { "field" : "obj.obj.obj.date", "range" : { "step" : 9, "unit" : "month", "bounds" : [ ISODate("2019-01-31T21:53:45.323Z"), ISODate("2020-06-02T10:40:15.842Z") ] } } }, { "$sort" : { "obj.obj.obj.date" : 1, "_id" : 1 } }, { "$limit" : 1000 } ])
      // Result:
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-01-30T21:53:45.323Z") } } } }
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-01-31T21:53:45.323Z") } } } }
      // { "_id" : ObjectId("6772948fbfb88c160d07a21e"), "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-10-01T00:00:00Z") } } } }
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-10-31T21:53:45.323Z") } } } }
      // ------
      // Worse yet the number of erroneous documents is linear in the number of intermediary documents
      db.a.insert({obj: {obj: {obj: {date: new Date("2019-10-01")}}}})
      db.a.aggregate([ { "$densify" : { "field" : "obj.obj.obj.date", "range" : { "step" : 9, "unit" : "month", "bounds" : [ ISODate("2019-01-31T21:53:45.323Z"), ISODate("2020-06-02T10:40:15.842Z") ] } } }, { "$sort" : { "obj.obj.obj.date" : 1, "_id" : 1 } }, { "$limit" : 1000 } ])
      // Result:
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-01-30T21:53:45.323Z") } } } }
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-01-30T21:53:45.323Z") } } } }
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-01-31T21:53:45.323Z") } } } }
      // { "_id" : ObjectId("6772948fbfb88c160d07a21e"), "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-10-01T00:00:00Z") } } } }
      // { "_id" : ObjectId("677294cbbfb88c160d07a220"), "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-10-01T00:00:00Z") } } } }
      // { "obj" : { "obj" : { "obj" : { "date" : ISODate("2019-10-31T21:53:45.323Z") } } } } 
      

            Assignee:
            naama.bareket@mongodb.com Naama Bareket
            Reporter:
            samuel.mercier@mongodb.com Sam Mercier
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: