[SERVER-54565] date field gets flipped to "now" after set with $min in upsert Created: 13/Feb/21  Updated: 17/Mar/21  Resolved: 17/Mar/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.4.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Peter Billen Assignee: Edwin Zhou
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

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.

 

Participants:

 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 



 Comments   
Comment by Edwin Zhou [ 17/Mar/21 ]

Hi peter.billen@gmail.com,

We haven’t heard back from you for some time, so I’m going to close this ticket. If this is still an issue for you, please provide additional information and we will reopen the ticket.

Best,
Edwin

Comment by Edwin Zhou [ 08/Mar/21 ]

Hi peter.billen@gmail.com,

We still need additional information to diagnose the problem. If this is still an issue for you, would you please

  1. Run

    db.setLogLevel(1, "command")
    

    so we can better diagnose the issue.

  2. Reattempt your reproduction.
  3. Attach the log files including the timestamp of your reproduction.
  4. Let us know which version you're using to reproduce this issue.

Thanks,
Edwin

Comment by Edwin Zhou [ 16/Feb/21 ]

Hi peter.billen@gmail.com,

Thanks for providing a detailed reproduction for your issue. I am unable to reproduce the issue with my following script:

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

First and successive calls of coll.find({}) returns

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

Can you please:

  1. Run

    db.setLogLevel(1, "command")
    

    so we can better diagnose the issue.

  1. Reattempt your reproduction.
  2. Attach the log files including the timestamp of your reproduction.
  3. Let us know which version you're using to reproduce this issue.

Thanks,
Edwin

Comment by Peter Billen [ 13/Feb/21 ]

My apologies for the formatting in the reproduce steps, but apparently I cannot edit my ticket anymore.

Generated at Thu Feb 08 05:33:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.