This commit is contained in:
2020-08-20 11:44:32 +02:00
parent 4715fc1814
commit 6aceefeb2f
2891 changed files with 11239 additions and 347539 deletions

55
node_modules/mongoose/lib/query.js generated vendored
View File

@@ -1293,6 +1293,7 @@ Query.prototype.getOptions = function() {
* - [writeConcern](https://docs.mongodb.com/manual/reference/method/db.collection.update/)
* - [timestamps](https://mongoosejs.com/docs/guide.html#timestamps): If `timestamps` is set in the schema, set this option to `false` to skip timestamps for that particular update. Has no effect if `timestamps` is not enabled in the schema options.
* - omitUndefined: delete any properties whose value is `undefined` when casting an update. In other words, if this is set, Mongoose will delete `baz` from the update in `Model.updateOne({}, { foo: 'bar', baz: undefined })` before sending the update to the server.
* - overwriteDiscriminatorKey: allow setting the discriminator key in the update. Will use the correct discriminator schema if the update changes the discriminator key.
*
* The following options are only for `find()`, `findOne()`, `findById()`, `findOneAndUpdate()`, and `findByIdAndUpdate()`:
*
@@ -1361,6 +1362,10 @@ Query.prototype.setOptions = function(options, overwrite) {
this._mongooseOptions.setDefaultsOnInsert = options.setDefaultsOnInsert;
delete options.setDefaultsOnInsert;
}
if ('overwriteDiscriminatorKey' in options) {
this._mongooseOptions.overwriteDiscriminatorKey = options.overwriteDiscriminatorKey;
delete options.overwriteDiscriminatorKey;
}
return Query.base.setOptions.call(this, options);
};
@@ -2999,19 +3004,24 @@ Query.prototype.findOneAndUpdate = function(criteria, doc, options, callback) {
this._mergeUpdate(doc);
}
if (options) {
options = utils.clone(options);
if (options.projection) {
this.select(options.projection);
delete options.projection;
}
if (options.fields) {
this.select(options.fields);
delete options.fields;
}
options = options ? utils.clone(options) : {};
this.setOptions(options);
if (options.projection) {
this.select(options.projection);
delete options.projection;
}
if (options.fields) {
this.select(options.fields);
delete options.fields;
}
const returnOriginal = get(this, 'model.base.options.returnOriginal');
if (options.returnOriginal == null && returnOriginal != null) {
options.returnOriginal = returnOriginal;
}
this.setOptions(options);
if (!callback) {
return this;
@@ -3330,7 +3340,14 @@ Query.prototype.findOneAndReplace = function(filter, replacement, options, callb
this._mergeUpdate(replacement);
}
options && this.setOptions(options);
options = options || {};
const returnOriginal = get(this, 'model.base.options.returnOriginal');
if (options.returnOriginal == null && returnOriginal != null) {
options.returnOriginal = returnOriginal;
}
this.setOptions(options);
if (!callback) {
return this;
@@ -4485,6 +4502,19 @@ Query.prototype._post = function(fn) {
Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
let strict;
let schema = this.schema;
const discriminatorKey = schema.options.discriminatorKey;
const baseSchema = schema._baseSchema ? schema._baseSchema : schema;
if (this._mongooseOptions.overwriteDiscriminatorKey &&
obj[discriminatorKey] != null &&
baseSchema.discriminators) {
const _schema = baseSchema.discriminators[obj[discriminatorKey]];
if (_schema != null) {
schema = _schema;
}
}
if ('strict' in this._mongooseOptions) {
strict = this._mongooseOptions.strict;
} else if (this.schema && this.schema.options) {
@@ -4508,7 +4538,6 @@ Query.prototype._castUpdate = function _castUpdate(obj, overwrite) {
upsert = this.options.upsert;
}
let schema = this.schema;
const filter = this._conditions;
if (schema != null &&
utils.hasUserDefinedProperty(filter, schema.options.discriminatorKey) &&