Comparing version 7.6.6 to 7.6.7
@@ -57,3 +57,3 @@ 'use strict'; | ||
if (options && options.minimize && isSingleNested && Object.keys(ret).length === 0) { | ||
if (options && options.minimize && !obj.constructor.$__required && isSingleNested && Object.keys(ret).length === 0) { | ||
return undefined; | ||
@@ -60,0 +60,0 @@ } |
@@ -42,4 +42,6 @@ 'use strict'; | ||
let i; | ||
let setValueIndex = 0; | ||
function setValue(val) { | ||
++setValueIndex; | ||
if (count) { | ||
@@ -84,2 +86,4 @@ return val; | ||
return valueFilter([val], options, populateOptions, _allIds); | ||
} else if (o.justOne === true && !Array.isArray(val) && Array.isArray(_allIds)) { | ||
return valueFilter(val, options, populateOptions, val == null ? val : _allIds[setValueIndex - 1]); | ||
} | ||
@@ -90,2 +94,3 @@ return valueFilter(val, options, populateOptions, _allIds); | ||
for (i = 0; i < docs.length; ++i) { | ||
setValueIndex = 0; | ||
const _path = o.path.endsWith('.$*') ? o.path.slice(0, -3) : o.path; | ||
@@ -92,0 +97,0 @@ const existingVal = mpath.get(_path, docs[i], lookupLocalFields); |
@@ -15,9 +15,8 @@ 'use strict'; | ||
const keys = Object.keys(projection); | ||
let ki = keys.length; | ||
let exclude = null; | ||
if (ki === 1 && keys[0] === '_id') { | ||
if (keys.length === 1 && keys[0] === '_id') { | ||
exclude = !projection._id; | ||
} else { | ||
while (ki--) { | ||
for (let ki = 0; ki < keys.length; ++ki) { | ||
// Does this projection explicitly define inclusion/exclusion? | ||
@@ -24,0 +23,0 @@ // Explicitly avoid `$meta` and `$slice` |
@@ -35,2 +35,3 @@ 'use strict'; | ||
const SetOptionError = require('./error/setOptionError'); | ||
const applyEmbeddedDiscriminators = require('./helpers/discriminator/applyEmbeddedDiscriminators'); | ||
@@ -633,2 +634,4 @@ const defaultMongooseSymbol = Symbol.for('mongoose:default'); | ||
applyEmbeddedDiscriminators(schema); | ||
return model; | ||
@@ -635,0 +638,0 @@ }; |
@@ -183,7 +183,8 @@ 'use strict'; | ||
} | ||
// `_id: 1, name: 0` is a mixed inclusive/exclusive projection in | ||
// MongoDB 4.0 and earlier, but not in later versions. | ||
if (keys[keyIndex] === '_id' && keys.length > 1) { | ||
continue; | ||
} | ||
if (keys[keyIndex] === schema.options.discriminatorKey && keys.length > 1 && field != null && !field) { | ||
continue; | ||
} | ||
exclude = !field; | ||
@@ -190,0 +191,0 @@ break; |
@@ -10,3 +10,2 @@ 'use strict'; | ||
const castBigInt = require('../cast/bigint'); | ||
const utils = require('../utils'); | ||
@@ -181,3 +180,4 @@ /** | ||
SchemaBigInt.$conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
SchemaBigInt.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$gt: handleSingle, | ||
@@ -187,3 +187,3 @@ $gte: handleSingle, | ||
$lte: handleSingle | ||
}); | ||
}; | ||
@@ -190,0 +190,0 @@ /*! |
@@ -10,3 +10,2 @@ 'use strict'; | ||
const castBoolean = require('../cast/boolean'); | ||
const utils = require('../utils'); | ||
@@ -239,4 +238,3 @@ /** | ||
SchemaBoolean.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, {}); | ||
SchemaBoolean.$conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers }; | ||
@@ -243,0 +241,0 @@ /** |
@@ -253,13 +253,13 @@ /*! | ||
SchemaBuffer.prototype.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
$bitsAllClear: handleBitwiseOperator, | ||
$bitsAnyClear: handleBitwiseOperator, | ||
$bitsAllSet: handleBitwiseOperator, | ||
$bitsAnySet: handleBitwiseOperator, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}); | ||
SchemaBuffer.prototype.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$bitsAllClear: handleBitwiseOperator, | ||
$bitsAnyClear: handleBitwiseOperator, | ||
$bitsAllSet: handleBitwiseOperator, | ||
$bitsAnySet: handleBitwiseOperator, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}; | ||
@@ -266,0 +266,0 @@ /** |
@@ -391,9 +391,9 @@ /*! | ||
SchemaDate.prototype.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}); | ||
SchemaDate.prototype.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}; | ||
@@ -400,0 +400,0 @@ |
@@ -10,3 +10,2 @@ /*! | ||
const castDecimal128 = require('../cast/decimal128'); | ||
const utils = require('../utils'); | ||
const isBsonType = require('../helpers/isBsonType'); | ||
@@ -218,9 +217,9 @@ | ||
Decimal128.prototype.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}); | ||
Decimal128.prototype.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}; | ||
@@ -227,0 +226,0 @@ /*! |
@@ -91,8 +91,2 @@ 'use strict'; | ||
this.$embeddedSchemaType.schema = this.schema; | ||
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) { | ||
for (const disc of schema._applyDiscriminators.keys()) { | ||
this.discriminator(disc, schema._applyDiscriminators.get(disc)); | ||
} | ||
} | ||
} | ||
@@ -532,3 +526,3 @@ | ||
const options = Object.assign({}, this.options); | ||
const schematype = new this.constructor(this.path, this.schema, { ...options, _skipApplyDiscriminators: true }, this.schemaOptions); | ||
const schematype = new this.constructor(this.path, this.schema, options, this.schemaOptions); | ||
schematype.validators = this.validators.slice(); | ||
@@ -535,0 +529,0 @@ if (this.requiredValidator !== undefined) { |
@@ -402,14 +402,14 @@ 'use strict'; | ||
SchemaNumber.prototype.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
$bitsAllClear: handleBitwiseOperator, | ||
$bitsAnyClear: handleBitwiseOperator, | ||
$bitsAllSet: handleBitwiseOperator, | ||
$bitsAnySet: handleBitwiseOperator, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle, | ||
$mod: handleArray | ||
}); | ||
SchemaNumber.prototype.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$bitsAllClear: handleBitwiseOperator, | ||
$bitsAnyClear: handleBitwiseOperator, | ||
$bitsAllSet: handleBitwiseOperator, | ||
$bitsAnySet: handleBitwiseOperator, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle, | ||
$mod: handleArray | ||
}; | ||
@@ -416,0 +416,0 @@ /** |
@@ -262,9 +262,9 @@ /*! | ||
ObjectId.prototype.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}); | ||
ObjectId.prototype.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$gt: handleSingle, | ||
$gte: handleSingle, | ||
$lt: handleSingle, | ||
$lte: handleSingle | ||
}; | ||
@@ -271,0 +271,0 @@ /*! |
@@ -644,3 +644,4 @@ 'use strict'; | ||
const $conditionalHandlers = utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
const $conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$all: handleArray, | ||
@@ -660,3 +661,3 @@ $gt: handleSingle, | ||
$not: handleSingle | ||
}); | ||
}; | ||
@@ -663,0 +664,0 @@ Object.defineProperty(SchemaString.prototype, '$conditionalHandlers', { |
@@ -51,3 +51,3 @@ 'use strict'; | ||
this.caster = _createConstructor(schema); | ||
this.caster = _createConstructor(schema, null, options); | ||
this.caster.path = path; | ||
@@ -59,7 +59,2 @@ this.caster.prototype.$basePath = path; | ||
SchemaType.call(this, path, options, 'Embedded'); | ||
if (schema._applyDiscriminators != null && !options?._skipApplyDiscriminators) { | ||
for (const disc of schema._applyDiscriminators.keys()) { | ||
this.discriminator(disc, schema._applyDiscriminators.get(disc)); | ||
} | ||
} | ||
} | ||
@@ -79,3 +74,3 @@ | ||
function _createConstructor(schema, baseClass) { | ||
function _createConstructor(schema, baseClass, options) { | ||
// lazy load | ||
@@ -100,2 +95,3 @@ Subdocument || (Subdocument = require('../types/subdocument')); | ||
_embedded.prototype.constructor = _embedded; | ||
_embedded.$__required = options?.required; | ||
_embedded.base = schema.base; | ||
@@ -102,0 +98,0 @@ _embedded.schema = schema; |
@@ -316,4 +316,4 @@ /*! | ||
SchemaUUID.prototype.$conditionalHandlers = | ||
utils.options(SchemaType.prototype.$conditionalHandlers, { | ||
SchemaUUID.prototype.$conditionalHandlers = { | ||
...SchemaType.prototype.$conditionalHandlers, | ||
$bitsAllClear: handleBitwiseOperator, | ||
@@ -331,3 +331,3 @@ $bitsAnyClear: handleBitwiseOperator, | ||
$nin: handleArray | ||
}); | ||
}; | ||
@@ -334,0 +334,0 @@ /** |
@@ -230,30 +230,3 @@ 'use strict'; | ||
/** | ||
* Shallow copies defaults into options. | ||
* | ||
* @param {Object} defaults | ||
* @param {Object} [options] | ||
* @return {Object} the merged object | ||
* @api private | ||
*/ | ||
exports.options = function(defaults, options) { | ||
const keys = Object.keys(defaults); | ||
let i = keys.length; | ||
let k; | ||
options = options || {}; | ||
while (i--) { | ||
k = keys[i]; | ||
if (!(k in options)) { | ||
options[k] = defaults[k]; | ||
} | ||
} | ||
return options; | ||
}; | ||
/** | ||
* Merges `from` into `to` without overwriting existing properties. | ||
@@ -691,8 +664,2 @@ * | ||
/** | ||
* @see exports.options | ||
*/ | ||
exports.object.shallowCopy = exports.options; | ||
const hop = Object.prototype.hasOwnProperty; | ||
@@ -699,0 +666,0 @@ |
{ | ||
"name": "mongoose", | ||
"description": "Mongoose MongoDB ODM", | ||
"version": "7.6.6", | ||
"version": "7.6.7", | ||
"author": "Guillermo Rauch <guillermo@learnboost.com>", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -570,2 +570,6 @@ declare module 'mongoose' { | ||
>; | ||
findByIdAndRemove<ResultDoc = THydratedDocumentType>( | ||
id?: mongodb.ObjectId | any, | ||
options?: QueryOptions<TRawDocType> | null | ||
): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOneAndDelete'>; | ||
@@ -572,0 +576,0 @@ /** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2662791
281
49545