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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: 4.4.3
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      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.  

      Description

      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 

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: