Reputation: 11
Hi I am trying to get the aggregated count for the last 30 days of records.
To achieve this I am using the below $match
condition in Mongo aggregation pipeline
$match
{
"stageStartDate":{$gt: [new Date(ISODate().getTime() - 1000*60*60*24*30)]}
}
Error on Execution: Invalid Date Format at ISODate()
Please help me in solving this. I can't use Javascript, as I am directly calling this query in Jaspersoft reports.
Upvotes: 1
Views: 4322
Reputation: 1288
This should work, just create a new date object from milliseconds difference
db.collection.aggregate([{$match: {stageStartDate: {$gt: new Date(new Date(ISODate().getTime() - 1000*60*60*24*30))}}}]);
Upvotes: 2