[SERVER-9289] Date operators incorrectly throw exceptions for object arguments Created: 08/Apr/13  Updated: 11/Jul/16  Resolved: 24/Sep/13

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.4.1
Fix Version/s: 2.5.3

Type: Bug Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-8924 Result of date plus millseconds canno... Closed
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

> 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

Participants:

 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.



 Comments   
Comment by Mathias Stearn [ 24/Sep/13 ]

This was fixed during an earlier refactor. Just added tests to ensure it stays fixed.

Comment by auto [ 24/Sep/13 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: Test for SERVER-9289 Date operators taking subexpression directly

The bug was fixed in earlier refactoring of Expression parsing.
Branch: master
https://github.com/mongodb/mongo/commit/14837002ef926c56f9ac3683127325833885594f

Comment by auto [ 19/Aug/13 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: Unify agg Expression parsing to eliminate special cases

Also fixes SERVER-9289: allowing objects as unwrapped single arguments
Branch: master
https://github.com/mongodb/mongo/commit/a852f2a5f1d575ed7a20adfc63bbf4c04151ba5e

Comment by Mathias Stearn [ 08/Apr/13 ]

This applies to any single-argument expression. To pass a subexpression as a single argument, it will need to wrapped in an array (of one element).

Generated at Thu Feb 08 03:19:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.