Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-2294

Incorrect sample code creating Date object

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 01112017-cleanup
    • None
    • None
    • None

    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.

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            joanna.cheng@mongodb.com Joanna Cheng
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 11 weeks, 1 day ago