Skip to content

Commit aa64400

Browse files
Merge branch 'Automattic:master' into fix-findOneAndUpdate-empty-filter
2 parents b826ca2 + 9702ac2 commit aa64400

File tree

7 files changed

+35
-8
lines changed

7 files changed

+35
-8
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
8.14.2 / 2025-05-08
2+
===================
3+
* fix(query): handle casting array filter paths underneath array filter paths with embedded discriminators #15388 #15386
4+
* docs(typescript): correct schema and model generic params in TS virtuals docs #15391
5+
* docs+types(schema): add alternative optimisticConcurrency syntaxes to docs + types #15405 #10591
6+
* chore: add Node 24 to CI matrix #15408 [stscoundrel](https://github.com/stscoundrel)
7+
18
7.8.7 / 2025-04-30
29
==================
3-
* types(aggregate): allow calling project() with a string #15304 #15300
4-
* docs: update deleteOne & deleteMany API def #15360 [Elliot67](https://github.com/Elliot67) [SethFalco](https://github.com/SethFalco)
10+
* types(aggregate): allow calling project() with a string #15304 #15300
11+
* docs: update deleteOne & deleteMany API def #15360 [Elliot67](https://github.com/Elliot67) [SethFalco](https://github.com/SethFalco)
512

613
8.14.1 / 2025-04-29
714
===================

lib/schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const numberRE = /^\d+$/;
7777
* - [validateBeforeSave](https://mongoosejs.com/docs/guide.html#validateBeforeSave) - bool - defaults to `true`
7878
* - [validateModifiedOnly](https://mongoosejs.com/docs/api/document.html#Document.prototype.validate()) - bool - defaults to `false`
7979
* - [versionKey](https://mongoosejs.com/docs/guide.html#versionKey): string or object - defaults to "__v"
80-
* - [optimisticConcurrency](https://mongoosejs.com/docs/guide.html#optimisticConcurrency): bool - defaults to false. Set to true to enable [optimistic concurrency](https://thecodebarbarian.com/whats-new-in-mongoose-5-10-optimistic-concurrency.html).
80+
* - [optimisticConcurrency](https://mongoosejs.com/docs/guide.html#optimisticConcurrency): bool or string[] or { exclude: string[] } - defaults to false. Set to true to enable [optimistic concurrency](https://thecodebarbarian.com/whats-new-in-mongoose-5-10-optimistic-concurrency.html). Set to string array to enable optimistic concurrency for only certain fields, or `{ exclude: string[] }` to define a list of fields to ignore for optimistic concurrency.
8181
* - [collation](https://mongoosejs.com/docs/guide.html#collation): object - defaults to null (which means use no collation)
8282
* - [timeseries](https://mongoosejs.com/docs/guide.html#timeseries): object - defaults to null (which means this schema's collection won't be a timeseries collection)
8383
* - [selectPopulatedPaths](https://mongoosejs.com/docs/guide.html#selectPopulatedPaths): boolean - defaults to `true`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mongoose",
33
"description": "Mongoose MongoDB ODM",
4-
"version": "8.14.1",
4+
"version": "8.14.2",
55
"author": "Guillermo Rauch <guillermo@learnboost.com>",
66
"keywords": [
77
"mongodb",

test/types/schema.test.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
Query,
2323
model,
2424
ValidateOpts,
25-
BufferToBinary
25+
BufferToBinary,
26+
CallbackWithoutResultAndOptionalError
2627
} from 'mongoose';
2728
import { Binary } from 'mongodb';
2829
import { IsPathRequired } from '../../types/inferschematype';
@@ -1778,6 +1779,22 @@ function gh15301() {
17781779
});
17791780
}
17801781

1782+
function gh15412() {
1783+
const ScheduleEntrySchema = new Schema({
1784+
startDate: { type: Date, required: true },
1785+
endDate: { type: Date, required: false }
1786+
});
1787+
const ScheduleEntry = model('ScheduleEntry', ScheduleEntrySchema);
1788+
1789+
type ScheduleEntryDoc = ReturnType<typeof ScheduleEntry['hydrate']>
1790+
1791+
ScheduleEntrySchema.post('init', function(this: ScheduleEntryDoc, _res: any, next: CallbackWithoutResultAndOptionalError) {
1792+
expectType<Date>(this.startDate);
1793+
expectType<Date | null | undefined>(this.endDate);
1794+
next();
1795+
});
1796+
}
1797+
17811798
function defaultReturnsUndefined() {
17821799
const schema = new Schema<{ arr: number[] }>({
17831800
arr: {

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ declare module 'mongoose' {
387387
post<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], fn: PostMiddlewareFunction<T, T>): this;
388388
post<T = THydratedDocumentType>(method: MongooseDistinctDocumentMiddleware|MongooseDistinctDocumentMiddleware[], options: SchemaPostOptions & SchemaPostOptions, fn: PostMiddlewareFunction<T, T>): this;
389389
post<T = THydratedDocumentType>(method: MongooseQueryOrDocumentMiddleware | MongooseQueryOrDocumentMiddleware[] | RegExp, options: SchemaPostOptions & { document: true, query: false }, fn: PostMiddlewareFunction<T, T>): this;
390+
post<T = THydratedDocumentType>(method: 'init', fn: PostMiddlewareFunction<T, T>): this;
391+
390392
// this = Query
391393
post<T = Query<any, any>>(method: MongooseRawResultQueryMiddleware|MongooseRawResultQueryMiddleware[], fn: PostMiddlewareFunction<T, null | QueryResultType<T> | ModifyResult<QueryResultType<T>>>): this;
392394
post<T = Query<any, any>>(method: MongooseDefaultQueryMiddleware|MongooseDefaultQueryMiddleware[], fn: PostMiddlewareFunction<T, QueryResultType<T>>): this;

types/schemaoptions.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ declare module 'mongoose' {
107107
/**
108108
* Optimistic concurrency is a strategy to ensure the document you're updating didn't change between when you
109109
* loaded it using find() or findOne(), and when you update it using save(). Set to `true` to enable
110-
* optimistic concurrency.
110+
* optimistic concurrency. Set to string array to enable optimistic concurrency for only certain fields,
111+
* or `{ exclude: string[] }` to define a list of fields to ignore for optimistic concurrency.
111112
*/
112-
optimisticConcurrency?: boolean;
113+
optimisticConcurrency?: boolean | string[] | { exclude: string[] };
113114
/**
114115
* If `plugin()` called with tags, Mongoose will only apply plugins to schemas that have
115116
* a matching tag in `pluginTags`

types/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ declare module 'mongoose' {
7070
create(obj: any): THydratedDocumentType;
7171

7272
/** Searches array items for the first document with a matching _id. */
73-
id(id: any): THydratedDocumentType | null;
73+
id(id: ObjectId | string | number | Buffer): THydratedDocumentType | null;
7474

7575
push(...args: (AnyKeys<T> & AnyObject)[]): number;
7676

0 commit comments

Comments
 (0)