[SERVER-37351] Add Date.prototype.toISOString() Created: 27/Sep/18  Updated: 27/Sep/18  Resolved: 27/Sep/18

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

Type: Bug Priority: Major - P3
Reporter: Igor Solodovnikov Assignee: Nick Brewer
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

start mongo shell and try to execute following commands:

u64vm(mongod-3.6.8) test> var d = Date()
u64vm(mongod-3.6.8) test> d
Thu Sep 27 2018 18:37:13 GMT+0300 (EEST)
u64vm(mongod-3.6.8) test> d.toString()
Thu Sep 27 2018 18:37:13 GMT+0300 (EEST)
u64vm(mongod-3.6.8) test> d.toISOString()
2018-09-27T18:37:29.057+0300 E QUERY [thread1] TypeError: d.toISOString is not a function :
@(shell):1:1

Participants:

 Description   

JavaScript in the mongo shell does not support toISOString() method on the Date object



 Comments   
Comment by Nick Brewer [ 27/Sep/18 ]

igorsol You can use:

var d = new Date()
d.toISOString()
2018-09-27T19:55:31.778Z

Per the Mozilla documentation:

JavaScript Date objects can only be instantiated by calling JavaScript Date as a constructor: calling it as a regular function (i.e. without the new operator) will return a string rather than a Date object; unlike other JavaScript object types, JavaScript Date objects have no literal syntax.

Since this doesn't represent a bug in MongoDB, I'll close this ticket. Let us know if you have any questions.

-Nick

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