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)
}
})