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

date field gets flipped to "now" after set with $min in upsert

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.3
    • Component/s: None
    • Labels:
      None
    • ALL
    • Hide

      Open shell and execute the three commands above in a fast manner:

       

      db.myCollection.remove({})
      db.myCollection.update({_id:"rxTY3n1RHf4qV6xA3E5ydXY="}, {   "$min":{     "scheduledAt":new Date("2020-12-01T10:00:00Z")   } },{upsert:true})
      db.myCollection.find({})
      

      Depending on timing, you get a correct or invalid value for the `scheduleAt` field.

       

      Show
      Open shell and execute the three commands above in a fast manner:   db.myCollection.remove({}) db.myCollection.update({_id: "rxTY3n1RHf4qV6xA3E5ydXY=" }, {   "$min" :{     "scheduledAt" : new Date( "2020-12-01T10:00:00Z" )   } },{upsert: true }) db.myCollection.find({}) Depending on timing, you get a correct or invalid value for the `scheduleAt` field.  

      Consider the follow sequence of three commands:

       

      db.myCollection.remove({})
      db.myCollection.update({_id:"rxTY3n1RHf4qV6xA3E5ydXY="},
      {
        "$min":{
          "scheduledAt":new Date("2020-12-01T10:00:00Z")
        }
      },{upsert:true})
      db.myCollection.find({})

      When the last `find()` is executed immedeality, I get:

       

      { "_id" : "rxTY3n1RHf4qV6xA3E5ydXY=", "scheduledAt" : ISODate("2020-12-01T10:00:00Z") } 
      

      However, after waiting a second or more, I get for find():

      { "_id" : "rxTY3n1RHf4qV6xA3E5ydXY=", "scheduledAt" : ISODate("2021-02-13T11:19:24.001Z") }

      Note that the `scheduledAt` field has been flipped to the current timestamp.

       

      The idea of the update query above is to only update `scheduledAt` when the given value is less than the current value. Initially (during the insert), the given value should be taken.

      This seems to work fine with other data types (such as integer), but not for the date data type.

      See also https://imgur.com/a/iGzKrDn 

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            peter.billen@gmail.com Peter Billen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: