[SERVER-8924] Result of date plus millseconds cannot be used within same project Created: 09/Mar/13  Updated: 10/Dec/14  Resolved: 09/Apr/13

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 2.4.0-rc2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-9289 Date operators incorrectly throw exce... Closed
Operating System: ALL
Participants:

 Description   

Normally you're allowed to "chain" or group together multiple operations in a single $project. This does not seem to work with dates and addition - even though result is a date it cannot be used in the same $project stage, but the next one:

 

spr@local(2.4.0-rc2) > db.testD.findOne()
{
"_id" : ObjectId("513b2a362d8edd2720469b86"),
"idate" : ISODate("2013-03-09T12:25:26.370Z")
}
spr@local(2.4.0-rc2) > db.testD.aggregate({$project:{ndate:{$add:["$idate",19800000]}}})
{
"result" : [

{ "_id" : ObjectId("513b2a362d8edd2720469b86"), "ndate" : ISODate("2013-03-09T17:55:26.370Z") }

],
"ok" : 1
}
spr@local(2.4.0-rc2) > db.testD.aggregate({$project:{ndate:{$add:["$idate",19800000]}}},{$project:{y:{$year:"$ndate"}}})
{
"result" : [

{ "_id" : ObjectId("513b2a362d8edd2720469b86"), "y" : 2013 }

],
"ok" : 1
}
// BUT
spr@local(2.4.0-rc2) > db.testD.aggregate({$project:{nyear:{$year:{$add:["$idate",19800000]}}}})
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:10
Sat Mar 9 12:38:17.001 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



 Comments   
Comment by Mathias Stearn [ 09/Apr/13 ]

This is a duplicate of SERVER-9289 and the workaround mentioned there will work here too (wrapping the $add object in a single element array).

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