| 4475 | const excludeIdRegGlobal = /\s?-_id\s?/g; |
| 4476 | |
| 4477 | async function _populatePath(model, docs, populateOptions) { |
| 4478 | if (populateOptions.strictPopulate == null) { |
| 4479 | if (populateOptions._localModel?.schema._userProvidedOptions.strictPopulate != null) { |
| 4480 | populateOptions.strictPopulate = populateOptions._localModel.schema._userProvidedOptions.strictPopulate; |
| 4481 | } else if (populateOptions._localModel != null && model.base.options.strictPopulate != null) { |
| 4482 | populateOptions.strictPopulate = model.base.options.strictPopulate; |
| 4483 | } else if (model.base.options.strictPopulate != null) { |
| 4484 | populateOptions.strictPopulate = model.base.options.strictPopulate; |
| 4485 | } |
| 4486 | } |
| 4487 | |
| 4488 | // normalize single / multiple docs passed |
| 4489 | if (!Array.isArray(docs)) { |
| 4490 | docs = [docs]; |
| 4491 | } |
| 4492 | if (docs.length === 0 || docs.every(utils.isNullOrUndefined)) { |
| 4493 | return; |
| 4494 | } |
| 4495 | |
| 4496 | const modelsMap = getModelsMapForPopulate(model, docs, populateOptions); |
| 4497 | if (modelsMap instanceof MongooseError) { |
| 4498 | throw modelsMap; |
| 4499 | } |
| 4500 | const len = modelsMap.length; |
| 4501 | let vals = []; |
| 4502 | |
| 4503 | function flatten(item) { |
| 4504 | // no need to include undefined values in our query |
| 4505 | return undefined !== item; |
| 4506 | } |
| 4507 | |
| 4508 | let hasOne = false; |
| 4509 | const params = []; |
| 4510 | for (let i = 0; i < len; ++i) { |
| 4511 | const mod = modelsMap[i]; |
| 4512 | let select = mod.options.select; |
| 4513 | let ids = utils.array.flatten(mod.ids, flatten); |
| 4514 | ids = utils.array.unique(ids); |
| 4515 | |
| 4516 | const assignmentOpts = {}; |
| 4517 | assignmentOpts.sort = mod && |
| 4518 | mod.options && |
| 4519 | mod.options.options && |
| 4520 | mod.options.options.sort || void 0; |
| 4521 | assignmentOpts.excludeId = excludeIdReg.test(select) || (select && select._id === 0); |
| 4522 | |
| 4523 | // Lean transform may delete `_id`, which would cause assignment |
| 4524 | // to fail. So delay running lean transform until _after_ |
| 4525 | // `_assign()` |
| 4526 | if (mod.options && |
| 4527 | mod.options.options && |
| 4528 | mod.options.options.lean && |
| 4529 | mod.options.options.lean.transform) { |
| 4530 | mod.options.options._leanTransform = mod.options.options.lean.transform; |
| 4531 | mod.options.options.lean = true; |
| 4532 | } |
| 4533 | |
| 4534 | if (ids.length === 0 || ids.every(utils.isNullOrUndefined)) { |