| 4036 | */ |
| 4037 | |
| 4038 | function _completeOneLean(schema, doc, path, res, opts, callback) { |
| 4039 | if (opts.lean && typeof opts.lean.transform === 'function') { |
| 4040 | opts.lean.transform(doc); |
| 4041 | |
| 4042 | for (let i = 0; i < schema.childSchemas.length; i++) { |
| 4043 | const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path; |
| 4044 | const _schema = schema.childSchemas[i].schema; |
| 4045 | const obj = mpath.get(childPath, doc); |
| 4046 | if (obj == null) { |
| 4047 | continue; |
| 4048 | } |
| 4049 | if (Array.isArray(obj)) { |
| 4050 | for (let i = 0; i < obj.length; i++) { |
| 4051 | opts.lean.transform(obj[i]); |
| 4052 | } |
| 4053 | } else { |
| 4054 | opts.lean.transform(obj); |
| 4055 | } |
| 4056 | _completeOneLean(_schema, obj, childPath, res, opts); |
| 4057 | } |
| 4058 | if (callback) { |
| 4059 | return callback(null, doc); |
| 4060 | } else { |
| 4061 | return; |
| 4062 | } |
| 4063 | } |
| 4064 | if (opts.includeResultMetadata) { |
| 4065 | return callback(null, res); |
| 4066 | } |
| 4067 | return callback(null, doc); |
| 4068 | } |
| 4069 | |
| 4070 | /*! |
| 4071 | * ignore |