| 4072 | */ |
| 4073 | |
| 4074 | function _completeManyLean(schema, docs, path, opts) { |
| 4075 | if (opts.lean && typeof opts.lean.transform === 'function') { |
| 4076 | for (const doc of docs) { |
| 4077 | opts.lean.transform(doc); |
| 4078 | } |
| 4079 | |
| 4080 | for (let i = 0; i < schema.childSchemas.length; i++) { |
| 4081 | const childPath = path ? path + '.' + schema.childSchemas[i].model.path : schema.childSchemas[i].model.path; |
| 4082 | const _schema = schema.childSchemas[i].schema; |
| 4083 | let doc = mpath.get(childPath, docs); |
| 4084 | if (doc == null) { |
| 4085 | continue; |
| 4086 | } |
| 4087 | doc = doc.flat(); |
| 4088 | for (let i = 0; i < doc.length; i++) { |
| 4089 | opts.lean.transform(doc[i]); |
| 4090 | } |
| 4091 | _completeManyLean(_schema, doc, childPath, opts); |
| 4092 | } |
| 4093 | } |
| 4094 | |
| 4095 | return docs; |
| 4096 | } |
| 4097 | /** |
| 4098 | * Override mquery.prototype._mergeUpdate to handle mongoose objects in |
| 4099 | * updates. |