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

Allow treating ObjectId type as date in $project phase

    Details

      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.

        Activity

        Hide
        dangayle Dan Gayle added a comment -
        Show
        dangayle Dan Gayle added a comment - This ticket referenced here: http://stackoverflow.com/questions/18691689/aggregate-mongodb-results-by-objectid-date/18882827
        Hide
        asya Asya Kamsky added a comment -

        I think providing access to getTimestamp() method of ObjectId() type would be equivalent functionality.

        Show
        asya Asya Kamsky added a comment - I think providing access to getTimestamp() method of ObjectId() type would be equivalent functionality.

          People

          • Votes:
            41 Vote for this issue
            Watchers:
            26 Start watching this issue

            Dates

            • Created:
              Updated: