Is there a way to access a Date as milliseconds since epoch (Date.getTime()) in mongodb aggregation pipeline -
mongodb provides lots of 'date aggregation operators' such $dayofyear, $dayof month, , $millisecond. $millisecond function returns milliseconds of time stamp range of 0-999.
is there way access date object milliseconds since epoch in aggregation pipeline?
thanks,
nathan
you can $subtract epoch date , result date milliseconds since epoch:
db.collection.aggregate([ {$project : { "dateinmillis" : {$subtract : ["$date", new date("1-1-1970")] } }} ]);
Comments
Post a Comment