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

Date operators incorrectly throw exceptions for object arguments

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor - P4
    • Resolution: Fixed
    • 2.4.1
    • 2.5.3
    • Aggregation Framework
    • None
    • Fully Compatible
    • ALL
    • Hide

      > db.foo.drop()
      > db.foo.insert({x:ISODate()})
      > db.foo.aggregate({$project: {x:1, y: {$year: [{$add:['$x',1000]}]}}})
      {
      	"result" : [
      		{
      			"_id" : ObjectId("516341333512acfb2d33f156"),
      			"x" : ISODate("2013-04-08T22:14:11.665Z"),
      			"y" : 2013
      		}
      	],
      	"ok" : 1
      }
      > db.foo.aggregate({$project: {x:1, y: {$year: {$add:['$x',1000]}}}}))
      Error: Printing Stack Trace
          at printStackTrace (src/mongo/shell/utils.js:37:7)
          at DBCollection.aggregate (src/mongo/shell/collection.js:897:1)
          at (shell):1:8
      Mon Apr  8 18:15:15.198 JavaScript execution failed: aggregate failed: {
      	"errmsg" : "exception: the $year operator does not accept an object as an operand",
      	"code" : 16021,
      	"ok" : 0
      } at src/mongo/shell/collection.js:L898

      Show
      > db.foo.drop() > db.foo.insert({x:ISODate()}) > db.foo.aggregate({$project: {x:1, y: {$year: [{$add:['$x',1000]}]}}}) { "result" : [ { "_id" : ObjectId("516341333512acfb2d33f156"), "x" : ISODate("2013-04-08T22:14:11.665Z"), "y" : 2013 } ], "ok" : 1 } > db.foo.aggregate({$project: {x:1, y: {$year: {$add:['$x',1000]}}}})) Error: Printing Stack Trace at printStackTrace (src/mongo/shell/utils.js:37:7) at DBCollection.aggregate (src/mongo/shell/collection.js:897:1) at (shell):1:8 Mon Apr 8 18:15:15.198 JavaScript execution failed: aggregate failed: { "errmsg" : "exception: the $year operator does not accept an object as an operand", "code" : 16021, "ok" : 0 } at src/mongo/shell/collection.js:L898

    Description

      The $year operator (and possibly others) throws an exception if the argument is an object (i.e. the result of a computation). Internally, it seems to be rejecting the argument due to legacy code for named arguments. Wrapping the object argument in an array bypasses the bug.

      Attachments

        Issue Links

          Activity

            People

              mathias@mongodb.com Mathias Stearn
              jmikola@mongodb.com Jeremy Mikola
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: