Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (o.isVirtual && !o.justOne && !Array.isArray(rawIds[i])) {
if (rawIds[i] == null) {
rawIds[i] = [];
} else {
rawIds[i] = [rawIds[i]];
}
} else if (o.isVirtual && o.justOne && Array.isArray(rawIds[i])) {
rawIds[i] = rawIds[i][0];
}
if (o.isVirtual && docs[i].constructor.name === 'model') {
// If virtual populate and doc is already init-ed, need to walk through
// the actual doc to set rather than setting `_doc` directly
mpath.set(o.path, rawIds[i], docs[i]);
} else {
var parts = o.path.split('.');
var cur = docs[i];
for (var j = 0; j < parts.length - 1; ++j) {
if (cur[parts[j]] == null) {
cur[parts[j]] = {};
}
cur = cur[parts[j]];
}
if (docs[i].$__) {
docs[i].populated(o.path, o.allIds[i], o.allOptions);
}
utils.setValue(o.path, rawIds[i], docs[i], setValue);
}
}
}
return this;
}
let schema;
const parts = path.split('.');
if (pathType === 'adhocOrUndefined' && strict) {
// check for roots that are Mixed types
let mixed;
for (i = 0; i < parts.length; ++i) {
const subpath = parts.slice(0, i + 1).join('.');
// If path is underneath a virtual, bypass everything and just set it.
if (i + 1 < parts.length && this.schema.pathType(subpath) === 'virtual') {
mpath.set(path, val, this);
return this;
}
schema = this.schema.path(subpath);
if (schema == null) {
continue;
}
if (schema instanceof MixedSchema) {
// allow changes to sub paths of mixed types
mixed = true;
break;
}
}
if (schema == null) {
!o.originalModel.schema._getVirtual(o.path)) {
continue;
}
if (o.isVirtual && !o.justOne && !Array.isArray(rawIds[i])) {
if (rawIds[i] == null) {
rawIds[i] = [];
} else {
rawIds[i] = [rawIds[i]];
}
}
if (o.isVirtual && docs[i].constructor.name === 'model') {
// If virtual populate and doc is already init-ed, need to walk through
// the actual doc to set rather than setting `_doc` directly
mpath.set(o.path, rawIds[i], docs[i]);
} else {
var parts = o.path.split('.');
var cur = docs[i];
for (var j = 0; j < parts.length - 1; ++j) {
if (cur[parts[j]] == null) {
cur[parts[j]] = {};
}
cur = cur[parts[j]];
}
if (docs[i].$__) {
docs[i].populated(o.path, o.allIds[i], o.allOptions);
}
utils.setValue(o.path, rawIds[i], docs[i], setValue);
}
}
}
}, err => {
if (!err) {
mpath.set(path, idArray, this)
}
return fn(err)
})
}
exports.setValue = function (path, val, obj, map) {
mpath.set(path, val, obj, '_doc', map);
}
exports.setValue = function(path, val, obj, map, _copying) {
mpath.set(path, val, obj, '_doc', map, _copying);
};
exports.setValue = function(path, val, obj, map) {
mpath.set(path, val, obj, '_doc', map);
};
exports.setValue = function(path, val, obj, map) {
mpath.set(path, val, obj, '_doc', map);
};
exports.setValue = function(path, val, obj, map, _copying) {
mpath.set(path, val, obj, '_doc', map, _copying);
};