Skip to content

Instantly share code, notes, and snippets.

@desaijay315
Created June 14, 2019 12:07
Show Gist options
  • Save desaijay315/bd406b7fd0d49169f3a1f7f28afc1d1c to your computer and use it in GitHub Desktop.
Save desaijay315/bd406b7fd0d49169f3a1f7f28afc1d1c to your computer and use it in GitHub Desktop.
router.get('/posts',authenticate, async (req,res) => {
//const _ispublished = req.query.published;
const match = {}
if(req.query.published){
match.published = req.query.published === 'true'
}
try {
await req.user.populate({
path:'posts',
match,
options:{
limit: parseInt(req.query.limit),
skip: parseInt(req.query.skip)
}
}).execPopulate()
res.send(req.user.posts)
} catch (error) {
res.status(500).send()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment