-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (29 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var populateObjForElement = require('./populateObjForElement');
module.exports = function populateOptionsPlugin(schema) {
schema.query.setPopulateOptions = function(optionsToSet, allowedOptions) {
// Population information is stored in _mongooseOptions.populate. Note
// that this data strucutre is a bit odd looking. The first level of
// keys are the names of the fields to be populated. After that, the
// data looks as you would expect.
// this._mongooseOptions.populate = {
// firstField: {
// path: "firstField"
// select: ['foo', 'bar']
// }
// secondField: {
// ...
// }
// }
if (this._mongooseOptions && this._mongooseOptions.populate) {
var keys = Object.keys(this._mongooseOptions.populate);
for (var i = 0; i < keys.length; i++) {
this._mongooseOptions.populate[keys[i]] = populateObjForElement(
this._mongooseOptions.populate[keys[i]],
optionsToSet,
allowedOptions
);
}
}
return this;
};
};