Skip to content

Commit 171e694

Browse files
committedNov 4, 2015
docs; deep populate docs (Fix #3528)
1 parent 0922d78 commit 171e694

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed
 

‎docs/populate.jade

+29-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,38 @@ block content
190190

191191
h3#populate_an_existing_mongoose_document Populating an existing document
192192
:markdown
193-
If we have an existing mongoose document and want to populate some of its paths, **mongoose >= 3.6** supports the [document#populate()](./api.html#document_Document-populate) method.
193+
If we have an existing mongoose document and want to populate some of its
194+
paths, **mongoose >= 3.6** supports the
195+
[document#populate()](./api.html#document_Document-populate) method.
194196

195197
h3#populate_multiple_documents Populating multiple existing documents
196198
:markdown
197-
If we have one or many mongoose documents or even plain objects (_like [mapReduce](./api.html#model_Model.mapReduce) output_), we may populate them using the [Model.populate()](./api.html#model_Model.populate) method available in **mongoose >= 3.6**. This is what `document#populate()` and `query#populate()` use to populate documents.
199+
If we have one or many mongoose documents or even plain objects
200+
(_like [mapReduce](./api.html#model_Model.mapReduce) output_), we may
201+
populate them using the [Model.populate()](./api.html#model_Model.populate)
202+
method available in **mongoose >= 3.6**. This is what `document#populate()`
203+
and `query#populate()` use to populate documents.
204+
205+
h3#deep-populate Populating across multiple levels
206+
:markdown
207+
Say you have a user schema which keeps track of the user's friends.
208+
:js
209+
var userSchema = new Schema({
210+
name: String,
211+
friends: [{ type: ObjectId, ref: 'User' }]
212+
});
213+
:markdown
214+
Populate lets you get a list of a user's friends, but what if you also
215+
wanted a user's friends of friends? Specify the `populate` option to tell
216+
mongoose to populate the `friends` array of all the user's friends:
217+
:js
218+
User.
219+
findOne({ name: 'Val' }).
220+
populate({
221+
path: 'friends',
222+
// Get friends of friends - populate the 'friends' array for every friend
223+
populate: { path: 'friends' }
224+
});
198225

199226
h3#next Next Up
200227
:markdown

0 commit comments

Comments
 (0)
Please sign in to comment.