Vladimir Vladimir - 4 months ago 13
Node.js Question

How to display data only which can populate[mongoose]

Is possible to display details from collection where has inside population

role: '4edd40c86762e0fb12000002'
?

recommendModel.find({
userId: userId
})
.populate('recommendedBy',{role: '4edd40c86762e0fb12000002'})
.exec(handle().many.bind(null, 'message', res));


So for result where
populate
return null I also don't need record from
recommendModel.find
for that

Answer

If I'm understanding your question correctly you could perform a filter after your populate in your .exec. Check out this answer for more details on the implementation.

Comments