I am currently working with a Prisma schema designed for a MongoDB database
model orders {
id String @id @default(auto()) @map("_id") @db.ObjectId
totalAmount Int
createdAt DateTime @db.Date
}
My goal is to perform a groupby operation based on dates, and calculate the sum of total amounts on a monthly basis. For example:
{
"January": 4567,
"February": 7785
}
I attempted to achieve this using the method provided in the documentation, but unfortunately, it did not work as expected:
const sales = await prisma.orders.groupBy({
by: ["createdAt"],
_sum: {
totalAmount: true,
},
orderBy: { createdAt: "desc" },
});
Can someone guide me on how I can successfully accomplish this task?