You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/populate.jade
+29-2
Original file line number
Diff line number
Diff line change
@@ -190,11 +190,38 @@ block content
190
190
191
191
h3#populate_an_existing_mongoose_document Populating an existing document
192
192
: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
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
0 commit comments