[DOCS-2294] Incorrect sample code creating Date object Created: 24/Nov/13  Updated: 11/Jan/17  Resolved: 03/Dec/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Joanna Cheng Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 10 years, 11 weeks, 1 day ago

 Description   

The documentation shows the following code sample:

db.log.events.insert( {
   "status": new Date('July 22, 2013: 13:00:00'),
   "logEvent": 2,
   "logMessage": "Success!",
} )

When I try it it doesn't recognise the date format

> db.irc.save( {
...    "status": new Date('July 22, 2013: 14:00:00'),
...    "logEvent": 2,
...    "logMessage": "Success!",
... } )
> db.irc.find()
{ "_id" : ObjectId("5292784f25b5e2f57d9bd763"), "status" : ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ"), "logEvent" : 2, "logMessage" : "Success!" }

Removing the colon after "2013" is the correct way.

> db.irc.save( {    "status": new Date('July 22, 2013 14:00:00'),    "logEvent": 2,    "logMessage": "Success!", } )
> db.irc.find()
{ "_id" : ObjectId("5292784f25b5e2f57d9bd763"), "status" : ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ"), "logEvent" : 2, "logMessage" : "Success!" }
{ "_id" : ObjectId("5292786625b5e2f57d9bd764"), "status" : ISODate("2013-07-22T04:00:00Z"), "logEvent" : 2, "logMessage" : "Success!" }

Note there are 2 code snippets on this page, both with the extra colon.



 Comments   
Comment by Githook User [ 03/Dec/13 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-2294 ttl tutorial
Branch: v2.4
https://github.com/mongodb/docs/commit/55bac25edcb0cdd2016da56e8c937f3550c5ddf6

Comment by Githook User [ 03/Dec/13 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-2294 ttl tutorial
Branch: master
https://github.com/mongodb/docs/commit/3d357c3f0ef3c3dd8c72676126c509e9b9ec33b5

Generated at Thu Feb 08 07:43:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.