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

Allow treating ObjectId type as date in $project phase

    Details

    • Backwards Compatibility:
      Fully Compatible

      Description

      Since ObjectId() encompasses an approximation of insertion date it would be helpful if _id/things of ObjectId() type could be operated/projected the same way as Datetime type object.

      {case}
      {$project:{$year:"$_id"}} would extract year out of ObjectId().getTimestamp equivalent.{case}

      One question would be whether ObjectId could be operated on directly via date/interval arithmetic. I.e. whether it can be used anywhere a date can be used returning a standard Datetime type as a result from say {$subtract:["$_id",86400000]} which can only return ts of one day before that ObjectId's timestamp.

        Issue Links

          Activity

          Hide
          malindar11@gmail.com rain added a comment -

          @Alice Bevan-McGregor, is $decomposeId operator available in aggregation framework? which mongodb version you are referring?

          Show
          malindar11@gmail.com rain added a comment - @Alice Bevan-McGregor, is $decomposeId operator available in aggregation framework? which mongodb version you are referring?
          Hide
          amcgregor Alice Bevan-McGregor added a comment -

          @rain I'm referring to a hypothetical actual solution to this problem. E.g. the approach MongoDB would need to take to resolve this (writing a new Expression handler to do the ObjectID decomposition). This is not a current feature.

          Show
          amcgregor Alice Bevan-McGregor added a comment - @rain I'm referring to a hypothetical actual solution to this problem. E.g. the approach MongoDB would need to take to resolve this (writing a new Expression handler to do the ObjectID decomposition). This is not a current feature.
          Hide
          malindar11@gmail.com rain added a comment -

          Ohh sorry, my bad . yes, that's what exactly I'm looking for

          Show
          malindar11@gmail.com rain added a comment - Ohh sorry, my bad . yes, that's what exactly I'm looking for
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'asya999', u'name': u'Asya Kamsky', u'email': u'asya999@gmail.com'}

          Message: SERVER-9406 treat ObjectId type as Date in aggregation date expressions

          Closes #1154

          Signed-off-by: Charlie Swanson <charlie.swanson@mongodb.com>
          Branch: master
          https://github.com/mongodb/mongo/commit/90c32254af51f11aa494bc061f0afe2669c1189d

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'asya999', u'name': u'Asya Kamsky', u'email': u'asya999@gmail.com'} Message: SERVER-9406 treat ObjectId type as Date in aggregation date expressions Closes #1154 Signed-off-by: Charlie Swanson <charlie.swanson@mongodb.com> Branch: master https://github.com/mongodb/mongo/commit/90c32254af51f11aa494bc061f0afe2669c1189d
          Hide
          amcgregor Alice Bevan-McGregor added a comment -

          So… still no way to explicitly target specific ObjectID elements, which would have totally been a generalized and more broadly useful solution to this issue? Guess I'll open another ticket…

          Show
          amcgregor Alice Bevan-McGregor added a comment - So… still no way to explicitly target specific ObjectID elements, which would have totally been a generalized and more broadly useful solution to this issue? Guess I'll open another ticket…

            People

            • Votes:
              43 Vote for this issue
              Watchers:
              27 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: