Skip to content

Instantly share code, notes, and snippets.

@barmgeat
Last active October 31, 2019 08:15
Show Gist options
  • Save barmgeat/ef050c67bcac03216b4e218aef788254 to your computer and use it in GitHub Desktop.
Save barmgeat/ef050c67bcac03216b4e218aef788254 to your computer and use it in GitHub Desktop.
router.get('/getOne', async(req, res) =>{
try {
if(!req.query.id){
throw {message: 'add the post id in the request'}
}
const id = req.query.id;
//be carful to add the the tags field name in the model
//and not the Model Name or ref
const post = await Post.findById(id).populate('tags');
res.status(200).json(post);
} catch (error) {
res.status(400).json({error: error.message})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment