Refactoring day1
This commit is contained in:
55
node_modules/mongoose/lib/query.js
generated
vendored
55
node_modules/mongoose/lib/query.js
generated
vendored
@@ -1293,7 +1293,6 @@ 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()`:
|
||||
*
|
||||
@@ -1362,10 +1361,6 @@ 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);
|
||||
};
|
||||
@@ -3004,24 +2999,19 @@ Query.prototype.findOneAndUpdate = function(criteria, doc, options, callback) {
|
||||
this._mergeUpdate(doc);
|
||||
}
|
||||
|
||||
options = options ? utils.clone(options) : {};
|
||||
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;
|
||||
}
|
||||
|
||||
if (options.projection) {
|
||||
this.select(options.projection);
|
||||
delete options.projection;
|
||||
this.setOptions(options);
|
||||
}
|
||||
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;
|
||||
@@ -3340,14 +3330,7 @@ Query.prototype.findOneAndReplace = function(filter, replacement, options, callb
|
||||
this._mergeUpdate(replacement);
|
||||
}
|
||||
|
||||
options = options || {};
|
||||
|
||||
const returnOriginal = get(this, 'model.base.options.returnOriginal');
|
||||
if (options.returnOriginal == null && returnOriginal != null) {
|
||||
options.returnOriginal = returnOriginal;
|
||||
}
|
||||
|
||||
this.setOptions(options);
|
||||
options && this.setOptions(options);
|
||||
|
||||
if (!callback) {
|
||||
return this;
|
||||
@@ -4502,19 +4485,6 @@ 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) {
|
||||
@@ -4538,6 +4508,7 @@ 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) &&
|
||||
|
||||
Reference in New Issue
Block a user