-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backend Aggregate Pipeline #10
Comments
API route handler const getMainThread = req.query.random
? getRandomMainThreads(parseInt(req.query.count) || 6)
: getMainThreads(); If req query key is random (True), getRandomMainThreads, else (False), getMainTreads |
Postman GET URL: http://localhost:3000/api/threads/mainThread?random=True { |
Actually Prisma does not support the aggregation pipeline syntax directly. Prisma query builder documentation - using cursor pagination Key points: |
{
"error": "Error: \nInvalid `prisma.mainThread.findMany()` invocation:\n\n{\n take: 6,\n orderBy: [\n {\n id: 'asc'\n }\n ],\n cursor: {\n id: 0\n ~\n },\n include: {\n branchThread: true\n }\n}\n\nArgument id: Got invalid value 0 on prisma.findManyMainThread. Provided Int, expected String.\n\n"
} Get all the mainThread ids first const entireIds = await prisma.mainThread.findMany({
select: {
id: true,
},
}); |
Mongodb documentation
$sample - randomly selects "n" of documents from the database
$lookup - performs an equality match on the localField to the foreignField from the documents of the from collection
$lookup syntax
The text was updated successfully, but these errors were encountered: