I wrote a MongoDB query to fetch orders that were closed on a given date (matching year and month):
const orders = await OrderModel.find({
$expr: {
$and: [
{ $eq: ['$entityId', entityId] },
{ $ne: ['$closingDate', null] },
{ $eq: [{ $year: '$closingDate' }, date.getFullYear()] },
{ $eq: [{ $month: '$closingDate' }, date.getMonth() + 1] },
],
},
}).lean();
Turns out my local MongoDB version (3.6
) is higher than the one on the dev environment (3.4.14
), and therefore $expr
isn't supported. Is there an alternative for older version I can use?
Note: I read the other thread regarding this topic, but I couldn't extract an answer from that as it covers a different use case.