Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Last active May 13, 2020 19:45
Show Gist options
  • Save sandrabosk/727c384618a84152817e7bcccceacf08 to your computer and use it in GitHub Desktop.
Save sandrabosk/727c384618a84152817e7bcccceacf08 to your computer and use it in GitHub Desktop.
// Example:
// User has an array of references to posts
// Posts have an array of references to comments
// Or Dani's example: https://github.com/webmad-shared/doublepopulate/blob/master/bin/seeds.js
router.get('/posts', (req, res, next) => {
Model.find()
.populate('oneProperty') // .populate("creator")
.populate({
path:'secondProperty', // .populate("comments")
populate:{
path:'author', // what are we populating inside "comments"
model:'User'// the property we are populating is actually which model
}
})
.then(x => res.send(x))
.catch(err => res.send(err))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment