[SERVER-40739] Why does min Date get converted to unix epoch on insert? Created: 19/Apr/19  Updated: 19/Jun/23  Resolved: 19/Jun/23

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

Type: Question Priority: Major - P3
Reporter: Shane Harvey Assignee: [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
Resolution: Won't Do Votes: 0
Labels: move-stm, sdp-backlog-purge
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Development Platform
Sprint: Dev Tools 2019-05-20, Dev Tools 2019-06-03
Participants:

 Description   

Semi-related to SERVER-40737, when inserting the min Date, Date(NumberLong("-9223372036854775808"), from the mongo shell it gets converted into ISODate("1970-01-01T00:00:00Z"). Is this intentional? I would expect it to error instead of silently converting the date.

MongoDB shell version v4.1.10-150-g8560239dba
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5222ca7a-9585-45c2-a322-a8abe6b72791") }
MongoDB server version: 4.1.10-150-g8560239dba
PRIMARY> db.test.insertOne({date: new Date(NumberLong("-9223372036854775808"))})
{
	"acknowledged" : true,
	"insertedId" : ObjectId("5cba186bc1feb27106e4c8b5")
}
PRIMARY> db.test.find()
{ "_id" : ObjectId("5cba186bc1feb27106e4c8b5"), "date" : ISODate("1970-01-01T00:00:00Z") }
PRIMARY> new Date(NumberLong("-9223372036854775808"))
ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ")



 Comments   
Comment by Alex Neben [ 19/Jun/23 ]

This has been identified as work that the SDP team won't do in the near term. Please reopen with a comment if you feel this work should be reprioritized and explain why.

Comment by Steven Vannelli [ 10/May/22 ]

Moving this ticket to the Backlog and removing the "Backlog" fixVersion as per our latest policy for using fixVersions.

Comment by Billy Donahue [ 14/May/19 ]

I wanted to convince myself of where the epoch conversion happens.
So a mongo shell command of:

> db.test.insertOne({goodDate: new Date(), badDate: new Date(NumberLong("-9223372036854775808"))})

Causes an instrumented mongod to produce:

write documents: { _id: ObjectId('5cdb0e344fbd0c658b5f5388'), goodDate: new Date(1557859892076), badDate: new Date(0) }

So it's happening in shell before the insert is sent.
Yeah, storage has nothing to do with it.

The src/mongo/shell/types.js JS code has nothing to do with it. There's no mangling of the Date class there.

This particular crazy year part: "0NaN" is because we're blindly zero-padding year to width 4.

Generated at Thu Feb 08 04:55:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.