I am using mongodb java driver thru maven repository (as below in pom.xml) to query transactions between date range with aggregate framwork. The java driver generates follo
You have to format the date before passing onto $match aggregate.
Order.aggregate([
{
$match: {
createdAt: {
$gte: new Date(req.body.startDate),
$lt: new Date(req.body.endDate)
}
}
},
{
$lookup: {
from: 'acbinstallerpayments',
localField: "_id",
foreignField: 'customerObjectID',
as: 'installerPaymentDetails'
}
}
]);
I got it solved by removing the ""
& $
prefix on the $date
field of in $match
.
For you remove the same for $date
, $gt
& $lte
So that it should look like
db.transactions.aggregate(
{ "$match" :
{
'created_at': {
$gt: "2001-04-12T12:00:00.000Z",
$lt: "2020-04-13T12:00:00.000Z"
}
}
});