79226936

Date: 2024-11-26 13:42:16
Score: 0.5
Natty:
Report link

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 }
            }
        }
    ]
})
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Mezantrop