Skip to content

Commit 6f2ac19

Browse files
committed
Merge branch '8.18' into vkarpov15/gh-10894
2 parents 858b0fa + a59c33b commit 6f2ac19

34 files changed

+393
-71
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
8.17.2 / 2025-08-18
2+
===================
3+
* fix: avoid Model.validate() hanging when all paths fail casting #15580 #15579 [piotracalski](https://github.com/piotracalski)
4+
* types(document): better support for flattenObjectIds and versionKey options for toObject() and toJSON() #15582 #15578
5+
* docs: fix docs jsdoc tags and add UUID to be listed #15585
6+
* docs(document): fix code sample that errors with "Cannot set properties of undefined" #15589
7+
8+
8.17.1 / 2025-08-07
9+
===================
10+
* fix(query): propagate read preference and read concern to populate if read() called after populate() #15567 #15553
11+
* fix(model): call correct function in autoSearchIndex #15569 #15565
12+
* fix(model): allow setting statics option on discriminator schema #15568 #15556
13+
* fix(model): remove unnecessary conversion of undefined -> null in findById #15566 #15551
14+
* types: allow passing in projections without as const #15564 #15557
15+
* types: support maxLength and minLength in SchemaTypeOptions #15570 #4720
16+
117
8.17.0 / 2025-07-30
218
===================
319
* feat: upgrade mongodb -> 6.18.0 #15552

docs/source/api.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const files = [
2929
'lib/schema/number.js',
3030
'lib/schema/objectId.js',
3131
'lib/schema/string.js',
32+
'lib/schema/uuid.js',
3233
'lib/options/schemaTypeOptions.js',
3334
'lib/options/schemaArrayOptions.js',
3435
'lib/options/schemaBufferOptions.js',
@@ -42,7 +43,8 @@ const files = [
4243
'lib/types/buffer.js',
4344
'lib/types/decimal128.js',
4445
'lib/types/map.js',
45-
'lib/types/array/methods/index.js'
46+
'lib/types/array/methods/index.js',
47+
'lib/types/uuid.js'
4648
];
4749

4850
/** @type {Map.<string, DocsObj>} */

docs/typescript/schemas.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ There are a few caveats for using automatic type inference:
3030

3131
1. You need to set `strictNullChecks: true` or `strict: true` in your `tsconfig.json`. Or, if you're setting flags at the command line, `--strictNullChecks` or `--strict`. There are [known issues](https://github.com/Automattic/mongoose/issues/12420) with automatic type inference with strict mode disabled.
3232
2. You need to define your schema in the `new Schema()` call. Don't assign your schema definition to a temporary variable. Doing something like `const schemaDefinition = { name: String }; const schema = new Schema(schemaDefinition);` will not work.
33-
3. Mongoose adds `createdAt` and `updatedAt` to your schema if you specify the `timestamps` option in your schema, *except* if you also specify `methods`, `virtuals`, or `statics`. There is a [known issue](https://github.com/Automattic/mongoose/issues/12807) with type inference with timestamps and methods/virtuals/statics options. If you use methods, virtuals, and statics, you're responsible for adding `createdAt` and `updatedAt` to your schema definition.
33+
3. Mongoose adds `createdAt` and `updatedAt` to your schema if you specify the `timestamps` option in your schema.
3434

3535
If you must define your schema separately, use [as const](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions) (`const schemaDefinition = { ... } as const;`) to prevent *type widening*. TypeScript will automatically widen types like `required: false` to `required: boolean`, which will cause Mongoose to assume the field is required. Using `as const` forces TypeScript to retain these types.
3636

lib/document.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,15 +4070,17 @@ Document.prototype.$__toObjectShallow = function $__toObjectShallow(schemaFields
40704070
*
40714071
* If you want to skip transformations, use `transform: false`:
40724072
*
4073-
* schema.options.toObject.hide = '_id';
4074-
* schema.options.toObject.transform = function (doc, ret, options) {
4075-
* if (options.hide) {
4076-
* options.hide.split(' ').forEach(function (prop) {
4077-
* delete ret[prop];
4078-
* });
4073+
* schema.options.toObject = {
4074+
* hide: '_id',
4075+
* transform: function(doc, ret, options) {
4076+
* if (options.hide) {
4077+
* options.hide.split(' ').forEach(function(prop) {
4078+
* delete ret[prop];
4079+
* });
4080+
* }
4081+
* return ret;
40794082
* }
4080-
* return ret;
4081-
* }
4083+
* };
40824084
*
40834085
* const doc = new Doc({ _id: 'anId', secret: 47, name: 'Wreck-it Ralph' });
40844086
* doc.toObject(); // { secret: 47, name: 'Wreck-it Ralph' }

lib/error/messages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ msg.Date.max = 'Path `{PATH}` ({VALUE}) is after maximum allowed value ({MAX}).'
4343
msg.String = {};
4444
msg.String.enum = '`{VALUE}` is not a valid enum value for path `{PATH}`.';
4545
msg.String.match = 'Path `{PATH}` is invalid ({VALUE}).';
46-
msg.String.minlength = 'Path `{PATH}` (`{VALUE}`) is shorter than the minimum allowed length ({MINLENGTH}).';
47-
msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`) is longer than the maximum allowed length ({MAXLENGTH}).';
46+
msg.String.minlength = 'Path `{PATH}` (`{VALUE}`, length {LENGTH}) is shorter than the minimum allowed length ({MINLENGTH}).';
47+
msg.String.maxlength = 'Path `{PATH}` (`{VALUE}`, length {LENGTH}) is longer than the maximum allowed length ({MAXLENGTH}).';

lib/model.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,6 +4304,10 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
43044304
let remaining = paths.size;
43054305

43064306
return new Promise((resolve, reject) => {
4307+
if (remaining === 0) {
4308+
return settle();
4309+
}
4310+
43074311
for (const path of paths) {
43084312
const schemaType = schema.path(path);
43094313
if (schemaType == null) {
@@ -4328,13 +4332,17 @@ Model.validate = async function validate(obj, pathsOrOptions, context) {
43284332
}, context, { path: path });
43294333
}
43304334

4335+
function settle() {
4336+
if (error) {
4337+
reject(error);
4338+
} else {
4339+
resolve(obj);
4340+
}
4341+
}
4342+
43314343
function _checkDone() {
43324344
if (--remaining <= 0) {
4333-
if (error) {
4334-
reject(error);
4335-
} else {
4336-
resolve(obj);
4337-
}
4345+
return settle();
43384346
}
43394347
}
43404348
});

lib/schema/array.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ function cast$elemMatch(val, context) {
654654
* For example, `$conditionalHandlers.$all` is the function Mongoose calls to cast `$all` filter operators.
655655
*
656656
* @property $conditionalHandlers
657+
* @memberOf SchemaArray
658+
* @instance
657659
* @api public
658660
*/
659661

lib/schema/bigint.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ SchemaBigInt.get = SchemaType.get;
100100
*
101101
* @param {Function} caster
102102
* @return {Function}
103-
* @function get
103+
* @function cast
104104
* @static
105105
* @api public
106106
*/
@@ -190,6 +190,8 @@ const $conditionalHandlers = {
190190
* For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
191191
*
192192
* @property $conditionalHandlers
193+
* @memberOf SchemaBigInt
194+
* @instance
193195
* @api public
194196
*/
195197

lib/schema/boolean.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ SchemaBoolean.get = SchemaType.get;
105105
*
106106
* @param {Function} caster
107107
* @return {Function}
108-
* @function get
108+
* @function cast
109109
* @static
110110
* @api public
111111
*/
@@ -242,6 +242,8 @@ const $conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
242242
* For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
243243
*
244244
* @property $conditionalHandlers
245+
* @memberOf SchemaBoolean
246+
* @instance
245247
* @api public
246248
*/
247249

lib/schema/buffer.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ const $conditionalHandlers = {
276276
* For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
277277
*
278278
* @property $conditionalHandlers
279+
* @memberOf SchemaBuffer
280+
* @instance
279281
* @api public
280282
*/
281283

0 commit comments

Comments
 (0)