Last active
May 13, 2020 19:45
-
-
Save sandrabosk/727c384618a84152817e7bcccceacf08 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
// 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