【发布时间】:2016-10-20 00:18:11
【问题描述】:
我正在使用这样的聚合管道:
Model.aggregate([
$project:{
expiry: moment("$date_expired").format('h')}]
,function(err,res){...});
"$date_expired" 是架构中的日期。
但是,当我尝试从上述聚合中获取结果时,出现错误
FieldPath \'Invalid date\' doesn\'t start with $
可能是什么错误,我该如何解决?
【问题讨论】:
-
不能在 Mongo 中使用
$hour聚合吗? docs.mongodb.com/manual/reference/operator/aggregation/hour -
是的,但我需要得到区别,所以我也必须使用
$substract。只是想要一个更简单的解决方案,因为我已经在我的应用中使用了 moment。
标签: javascript node.js mongodb date momentjs