what does .populate do in js node mongoose code example
Example 1: mongoose populate
Story.
findOne({ title: /casino royale/i }).
populate('author', 'name').
exec(function (err, story) {
if (err) return handleError(err);
console.log('The author is %s', story.author.name);
console.log('The authors age is %s', story.author.age);
});
Example 2: how to use mongoose populate
function getUserWithPosts(username){ return User.findOne({ username: username }) .populate('posts').exec((err, posts) => { console.log("Populated User " + posts); })}