Created
June 14, 2019 12:07
-
-
Save desaijay315/bd406b7fd0d49169f3a1f7f28afc1d1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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