Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
I'm trying to create and fetch quizzes for a particular user using userId as parameters

I'm trying to create and fetch quizzes in router using NodeJs, but it keeps fetching me quizzes of every user and not only the user that is logged in

const prefix = "/:userId/quizzes";

router.get(`${prefix}/my-quizzes`, userAuth, async (req, res) => {
  try {
    const quizes = await Quiz.find().populate({
      path: "category",
      select: ["name"],
    });

    res.send(quizes);
  } catch (error) {
    return res.status(404).json({
      message: "Can't fetch quizes !",
      success: false,
    });
  }
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to filter your collection inside the find

Something like

Quiz.find({"userId": userId})
about 4 years ago · Juan Pablo Isaza Report

0

You just need to add a query using the proper userId taken from the req.param, like so:

await Quiz.find({userId: req.param.userId})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!