Techstack:Next.js 14, MongoDB, Prisma ORM. I have a many documents in my DB but I need random 15 documents each time I request…
If I have to do the same thing using mongoose I can do this:
const selectedProjects = await Project.aggregate([
{ $sample: { size: 15 } },
]).exec();
How can I accomplish the same in Prisma ORM?
2
Answers
Well, I have to make a function which shuffles the array and gives back
Then called
Random results are not currently supported by Prisma. There’s an open feature request for it.