I was able to first output the working method to $expr
and then found the method for the usual $match
:
await this.prisma.productRelease.aggregateRaw({
pipeline: [
{
$match: {
marking: { $ne: EnumProductReleaseMarking.deleted },
created_at: {
$gte: { $date: startYear },
$lte: { $date: endYear }
}
}
},
{
$group: {
_id: {
month: { $month: '$created_at' }
},
totalAmount: { $sum: '$total_amount' },
totalSale: { $sum: '$total_sale' },
totalSwap: { $sum: '$total_swap' },
totalBonus: { $sum: '$total_bonus' },
count: { $sum: 1 }
}
}
]
})