Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aggregation Framework - Converting Unix Timestamp to ISODate [duplicate]

Say I have a collection with objects like this, where the ts property contains an Unix Timestamp.

{ 
  "_id" : ObjectId("50ef1e0f1e816a74ad835a5a"), 
  "ts" : 1357851660 
}

Is there a way to convert the ts field to an ISODate using the Aggregation Framework, so I can use the date operators ($dayOfYear, $dayOfMonth, ...)?

like image 354
Badaro Avatar asked Jan 10 '13 20:01

Badaro


1 Answers

All information and testing I could find out indicates this is not possible as of MongoDB 2.2.2. It's fairly easy to implement using Map/Reduce though.

Marking this as answered as this seems to be the best answer available right now, but I'm willing to review this in the future if new functionality is added to MongoDB to support this, or if someone comes up with a good workaround.

like image 90
Badaro Avatar answered Sep 27 '22 02:09

Badaro