Skip to content

Commit

Permalink
docs: explain selecting foreignField in populate virtuals
Browse files Browse the repository at this point in the history
Re: #4923
  • Loading branch information
vkarpov15 committed Jan 21, 2017
1 parent b01692a commit 5140e62
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/populate.jade
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,25 @@ block content
var BandSchema = new Schema({
name: String
}, { toJSON: { virtuals: true } });

:markdown
If you're using populate projections, make sure `foreignField` is included
in the projection.

:js
Band.
find({}).
populate({ path: 'members', select: 'name' }).
exec(function(error, bands) {
// Won't work, foreign field `band` is not selected in the projection
});

Band.
find({}).
populate({ path: 'members', select: 'name band' }).
exec(function(error, bands) {
// Works, foreign field `band` is selected
});

h3#next Next Up
:markdown
Expand Down

0 comments on commit 5140e62

Please sign in to comment.