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

Result of date plus millseconds cannot be used within same project

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.0-rc2
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: