[SERVER-21350] new Date function is not working Created: 09/Nov/15 Updated: 09/Jul/16 Resolved: 18/Nov/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Shell |
| Affects Version/s: | 3.2.0-rc2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | carl dong | Assignee: | DO NOT USE - Backlog - Platform Team |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Minor Change |
| Operating System: | ALL |
| Steps To Reproduce: | mongo --nodb MongoDB shell version: 3.2.0-rc2 |
| Participants: |
| Description |
|
Can't get date value with new Date() function with mongo shell client 3.2.0 rc2. MongoDB shell version: 3.2.0-rc2 Which should return ISODate("2015-10-31T16:00:00Z") . |
| Comments |
| Comment by carl dong [ 09/Nov/15 ] | |||||||
|
Thanks , I am going to modify the date format with "T". | |||||||
| Comment by Stennie Steneker (Inactive) [ 09/Nov/15 ] | |||||||
|
Hi Carl, Thanks for reporting! It looks like this is a parsing difference between the V8 JavaScript engine used in prior releases and the Spidermonkey engine used in MongoDB 3.2. The ECMAScript 5 Date constructor only defines support for RFC-2822 or ISO8601 date formats. The spec says that "other formats may be used, but results may be unexpected". If you use the ISO8601 formats of YYYY-MM-DD (just date) or YYYY-MM-DDThh::mm::ss (date and time) you should get the expected result. Note that ISO8601 requires a "T" as a delimiter within a date and time string:
If you aren't able easily change the format of your date strings, as a workaround I would suggest using the ISODate() constructor in the mongo shell:
The ISODate() function is a shell helper which was added to implement ISO date parsing in MongoDB before ES5-compliant JavaScript engines added support for ISO date strings in JavaScript's built-in Date() constructor. Regards, |