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

149
Views
Populate and exepopulate didn’t work in mongoose.js and Node.js project

I have this route, but it didn't give a result which I had expected. It gave the 200 code as a response.

And a console.log statement before populate is working, but after it is not. What did I miss to do or how should I be working with populate?

For more info :

In user model


userSchema.virtual('wishes',{
    ref:'Wishes',
    localField:"_id",
    foreignField:"owner"

})

In wishes model :

 owner:{
        type:monoogse.Schema.Types.ObjectId,
        required:true,
        ref:'users'
    }

The route :-

router.get("/wishlist", auth, async(req, res) => {

    const sort = {}, match = {};

    if(req.query.sortBy)
    {
        const parts = req.query.sortBy.split(':');
        sort[parts[0]] = parts[1] === 'dec' ? -1 : 1;
    }

    try
    {
        console.log("likes")
        // const tasks = await Task.find({owner: req.user._id});
        await req.user.populate(
        {
            path: 'wishes',
            //     match,
            //     options:{
            //         limit: parseInt(req.query.limit),
            //         skip: parseInt(req.query.skip),
            //         sort
            //  }

        }).execPopulate();

        console.log(req.user.likes, "likes")
        console.log("likes2")
        res.send(req.user.likes)
    }
    catch(e)
    {
        res.send(e)
    }
})
about 4 years ago · Juan Pablo Isaza
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!