有没有办法从mongodb聚合管道中的历元(Date.getTime())以毫秒为单位访问日期 [英] Is there a way to access a Date as milliseconds since epoch (Date.getTime()) in mongodb aggregation pipeline
本文介绍了有没有办法从mongodb聚合管道中的历元(Date.getTime())以毫秒为单位访问日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Mongodb提供了许多'日期聚合算子
',如 $ dayOfYear
, $ dayOf Month
和 $ millisecond
。 $ millisecond
函数只返回时间戳的毫秒数,范围为0-999。
Mongodb provides lots of 'Date Aggregation Operators
' such as $dayOfYear
, $dayOf Month
, and $millisecond
. The $millisecond
function just returns the milliseconds of the time stamp with a range of 0-999.
是否有
谢谢,
Nathan
推荐答案
你可以减去时代日期,结果将是你的日期从
You can $subtract the epoch date and the result will be your date milliseconds since epoch:
db.collection.aggregate([
{$project : {
"dateInMillis" : {$subtract : ["$date", new Date("1-1-1970")] }
}}
]);
这篇关于有没有办法从mongodb聚合管道中的历元(Date.getTime())以毫秒为单位访问日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文