π’πΎππΆ
PPrisma
β’Created by π’πΎππΆ on 9/9/2024 in #help-and-questions
Prisma (with MongoDB) sort based on their related field
Hi! How can I retrieve all users from the User model in Prisma (with MongoDB), and sort them based on their total points from the related ShadePoints model?
I am currently using Prisma with MongoDB, What is the best way to sort users by the sum of their related ShadePoints.points using Prisma? Is there an example using or an alternative approach?
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
shadePoints ShadePoints[]
}
model ShadePoints {
id String @id @default(auto()) @map("_id") @db.ObjectId
points Int
userId String @db.ObjectId
user User @relation(fields: [userId], references: [id])
}
1 replies