mongoose 7.3.0 → 7.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/query.js +25 -33
- package/lib/schematype.js +2 -2
- package/package.json +1 -1
package/lib/query.js
CHANGED
|
@@ -3608,55 +3608,47 @@ Query.prototype._findOneAndReplace = async function _findOneAndReplace() {
|
|
|
3608
3608
|
throw this.error();
|
|
3609
3609
|
}
|
|
3610
3610
|
|
|
3611
|
+
if ('strict' in this.options) {
|
|
3612
|
+
this._mongooseOptions.strict = this.options.strict;
|
|
3613
|
+
delete this.options.strict;
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3611
3616
|
const filter = this._conditions;
|
|
3612
3617
|
const options = this._optionsForExec();
|
|
3613
3618
|
this._applyTranslateAliases(options);
|
|
3614
3619
|
convertNewToReturnDocument(options);
|
|
3615
3620
|
|
|
3616
|
-
const
|
|
3617
|
-
if (
|
|
3618
|
-
|
|
3619
|
-
this._update = this._castUpdate(this._update, true);
|
|
3620
|
-
} catch (err) {
|
|
3621
|
-
const validationError = new ValidationError();
|
|
3622
|
-
validationError.errors[err.path] = err;
|
|
3623
|
-
throw validationError;
|
|
3624
|
-
}
|
|
3625
|
-
|
|
3626
|
-
let res = await this._collection.collection.findOneAndReplace(filter, this._update || {}, options);
|
|
3627
|
-
|
|
3628
|
-
for (const fn of this._transforms) {
|
|
3629
|
-
res = fn(res);
|
|
3630
|
-
}
|
|
3631
|
-
|
|
3632
|
-
const doc = res.value;
|
|
3633
|
-
return new Promise((resolve, reject) => {
|
|
3634
|
-
this._completeOne(doc, res, _wrapThunkCallback(this, (err, res) => {
|
|
3635
|
-
if (err) {
|
|
3636
|
-
return reject(err);
|
|
3637
|
-
}
|
|
3638
|
-
resolve(res);
|
|
3639
|
-
}));
|
|
3640
|
-
});
|
|
3621
|
+
const modelOpts = { skipId: true };
|
|
3622
|
+
if ('strict' in this._mongooseOptions) {
|
|
3623
|
+
modelOpts.strict = this._mongooseOptions.strict;
|
|
3641
3624
|
}
|
|
3642
3625
|
|
|
3626
|
+
const runValidators = _getOption(this, 'runValidators', false);
|
|
3643
3627
|
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3628
|
+
try {
|
|
3629
|
+
const update = new this.model(this._update, null, modelOpts);
|
|
3630
|
+
if (runValidators) {
|
|
3631
|
+
await update.validate();
|
|
3632
|
+
} else if (update.$__.validationError) {
|
|
3633
|
+
throw update.$__.validationError;
|
|
3634
|
+
}
|
|
3635
|
+
this._update = update.toBSON();
|
|
3636
|
+
} catch (err) {
|
|
3637
|
+
if (err instanceof ValidationError) {
|
|
3638
|
+
throw err;
|
|
3639
|
+
}
|
|
3640
|
+
const validationError = new ValidationError();
|
|
3641
|
+
validationError.errors[err.path] = err;
|
|
3642
|
+
throw validationError;
|
|
3650
3643
|
}
|
|
3651
3644
|
|
|
3652
|
-
let res = await this._collection.collection.findOneAndReplace(filter,
|
|
3645
|
+
let res = await this._collection.collection.findOneAndReplace(filter, this._update, options);
|
|
3653
3646
|
|
|
3654
3647
|
for (const fn of this._transforms) {
|
|
3655
3648
|
res = fn(res);
|
|
3656
3649
|
}
|
|
3657
3650
|
|
|
3658
3651
|
const doc = res.value;
|
|
3659
|
-
|
|
3660
3652
|
return new Promise((resolve, reject) => {
|
|
3661
3653
|
this._completeOne(doc, res, _wrapThunkCallback(this, (err, res) => {
|
|
3662
3654
|
if (err) {
|
package/lib/schematype.js
CHANGED
|
@@ -810,8 +810,8 @@ SchemaType.prototype.get = function(fn) {
|
|
|
810
810
|
* // adding many validators at a time
|
|
811
811
|
*
|
|
812
812
|
* const many = [
|
|
813
|
-
* { validator: validator,
|
|
814
|
-
* , { validator: anotherValidator,
|
|
813
|
+
* { validator: validator, message: 'uh oh' }
|
|
814
|
+
* , { validator: anotherValidator, message: 'failed' }
|
|
815
815
|
* ]
|
|
816
816
|
* new Schema({ name: { type: String, validate: many }});
|
|
817
817
|
*
|