Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-43360

$dateFromParts errors in an aggregation pipeline where the year is 0 and a sort is performed

    • Minor Change
    • ALL
    • Hide

      Create a new database and populate it with a few files:

      > db.test.find()
      { "_id" : ObjectId("5d7fff34f129dbeed236f6f3"), "val" : 1 }
      { "_id" : ObjectId("5d7fff39f129dbeed236f6f4"), "val" : 2 }
      { "_id" : ObjectId("5d7fff3df129dbeed236f6f5"), "val" : 3 }
      

      Run an aggregation command using `$dateFromParts` with a zero year:

      > db.runCommand({"aggregate":"test","pipeline":[{"$match":{"$expr":{"$dateFromParts":{"year":0,"minute":14,"millisecond":10,"timezone":"Asia/Aden"}}}},{"$sort":{"val":1}}],"cursor":{}}) 
      { 
          "ok" : 0,
          "errmsg" : "Could not convert date to string: date component was outside the supported range of 0-9999: -1", 
          "code" : 18537, 
          "codeName" : "Location18537" 
      }
      
      Show
      Create a new database and populate it with a few files: > db.test.find() { "_id" : ObjectId( "5d7fff34f129dbeed236f6f3" ), "val" : 1 } { "_id" : ObjectId( "5d7fff39f129dbeed236f6f4" ), "val" : 2 } { "_id" : ObjectId( "5d7fff3df129dbeed236f6f5" ), "val" : 3 } Run an aggregation command using `$dateFromParts` with a zero year: > db.runCommand({ "aggregate" : "test" , "pipeline" :[{ "$match" :{ "$expr" :{ "$dateFromParts" :{ "year" :0, "minute" :14, "millisecond" :10, "timezone" : "Asia/Aden" }}}},{ "$sort" :{ "val" :1}}], "cursor" :{}}) { "ok" : 0, "errmsg" : "Could not convert date to string: date component was outside the supported range of 0-9999: -1" , "code" : 18537, "codeName" : "Location18537" }
    • Query 2019-12-16, Query 2019-12-30
    • 14

      The similar $dateFromString expression does not err. The $dateFromParts expression will only err if there is a sort and the year is 0. The documentation says that the value 0 for year is supported. No error results if there are no documents in the database, and the error will occurr no matter what field is sorted on or the direction of the sort.

       

      The equivalent find expression will not produce an error.

            Assignee:
            justin.seyster@mongodb.com Justin Seyster
            Reporter:
            carl.worley@mongodb.com Raiden Worley (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: