var findLeastHistoryArticlePipeline = [{
'$group': {
'_id': { title: '$title' },
maxTime: { $max: '$timestamp' },
minTime: { $min: '$timestamp' }
}
},
{
'$project': {
'_id': 0,
'title': '$_id.title',
'age': { $subtract: ['$maxTime', '$minTime'] }
}
},
{
'$sort': { 'age': 1 }
},
{ '$limit': 1 }
]
I got this aggregation pipeline for my mongodb query. But the return result shows that an error
assert: command failed: { "ok" : 0, "errmsg" : "cant $subtract aString from a String", "code" : 16556 } : aggregate failed
It seems that the maxTime and minTime are regarded as String type.
I've tried use new Date('$maxTime') but the result turns out to be 0 all the time.
Any suggestions?
via lhan
No comments:
Post a Comment