Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1276

Date() function inserting dates offset by one month

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • No version
    • Affects Version/s: None
    • Component/s: Shell API
    • None
    • Not Needed

      Problem Statement/Rationale

       

      new Date(YYYY, MM, DD)

      I see in the manual that this is not one of the listed input formats for Date(), but I found it in a fairly recent support ticket and began using it until I noticed that it seems to create records one month into the future relative to the requested date.  I see the same behavior in both mongo and mongosh and with both pre- and post-epoch dates.  It seems like this input format should either generate an error or correctly insert the date.

      Steps to Reproduce

      M-DHWT3WY66X:Don dave.kotz$ mongosh --version

      1.5.1

       

      db.freshexport.insert(

      { topic: 'meteorite', status: 'found', due_date: new Date(1955, 12, 12) }

      )

       

      db.freshexport.find(

      {topic: 'meteorite'}

      )

       [

       

      {     _id: ObjectId("62d57fd4739c95f8f61fa63a"),     topic: 'meteorite',     status: 'found',     due_date: ISODate("1956-01-12T06:00:00.000Z")   }

       ]

       

       

      db.freshexport.insert(

      { topic: 'asteroid', status: 'found', due_date: new Date(1999, 12, 12) }

      )

       

      db.freshexport.find(

      {topic: 'asteroid'}

      )

       [

       

      {     _id: ObjectId("62d58550739c95f8f61fa63b"),     topic: 'asteroid',     status: 'found',     due_date: ISODate("2000-01-12T06:00:00.000Z")   }

       ]

       

      db.freshexport.insert(

      { topic: 'planetoid', status: 'spinning', due_date: new Date(1988, 11, 25) }

      )

       

      db.freshexport.find(

      {topic: 'planetoid'}

      )

       [ 

       

      {     _id: ObjectId("62d5be49739c95f8f61fa63c"),     topic: 'planetoid',     status: 'spinning',     due_date: ISODate("1988-12-25T06:00:00.000Z")   }

       ]

      Expected Results

      Correct date inserted or error generated

      Actual Results

      Wrong date inserted

      Additional Notes

      Any additional information that may be useful to include.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dave.kotz@mongodb.com Dave Kotz (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: