mongoose 8.16.5 → 8.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/mongoose.js CHANGED
@@ -855,6 +855,17 @@ Mongoose.prototype.nextConnectionId;
855
855
 
856
856
  Mongoose.prototype.Aggregate = Aggregate;
857
857
 
858
+ /**
859
+ * The Base Mongoose Collection class. `mongoose.Collection` extends from this class.
860
+ *
861
+ * @memberOf Mongoose
862
+ * @instance
863
+ * @method Collection
864
+ * @api public
865
+ */
866
+
867
+ Mongoose.prototype.BaseCollection = require('./collection');
868
+
858
869
  /**
859
870
  * The Mongoose Collection constructor
860
871
  *
@@ -895,6 +906,17 @@ Object.defineProperty(Mongoose.prototype, 'Connection', {
895
906
  }
896
907
  });
897
908
 
909
+ /**
910
+ * The Base Mongoose Connection class. `mongoose.Connection` extends from this class.
911
+ *
912
+ * @memberOf Mongoose
913
+ * @instance
914
+ * @method Connection
915
+ * @api public
916
+ */
917
+
918
+ Mongoose.prototype.BaseConnection = require('./connection');
919
+
898
920
  /**
899
921
  * The Mongoose version
900
922
  *
@@ -649,6 +649,14 @@ function cast$elemMatch(val, context) {
649
649
  return val;
650
650
  }
651
651
 
652
+ /**
653
+ * Contains the handlers for different query operators for this schema type.
654
+ * For example, `$conditionalHandlers.$all` is the function Mongoose calls to cast `$all` filter operators.
655
+ *
656
+ * @property $conditionalHandlers
657
+ * @api public
658
+ */
659
+
652
660
  const handle = SchemaArray.prototype.$conditionalHandlers = {};
653
661
 
654
662
  handle.$all = cast$all;
@@ -185,6 +185,14 @@ const $conditionalHandlers = {
185
185
  $lte: handleSingle
186
186
  };
187
187
 
188
+ /**
189
+ * Contains the handlers for different query operators for this schema type.
190
+ * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
191
+ *
192
+ * @property $conditionalHandlers
193
+ * @api public
194
+ */
195
+
188
196
  Object.defineProperty(SchemaBigInt.prototype, '$conditionalHandlers', {
189
197
  enumerable: false,
190
198
  value: $conditionalHandlers
@@ -237,6 +237,14 @@ SchemaBoolean.prototype.cast = function(value) {
237
237
 
238
238
  const $conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
239
239
 
240
+ /**
241
+ * Contains the handlers for different query operators for this schema type.
242
+ * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
243
+ *
244
+ * @property $conditionalHandlers
245
+ * @api public
246
+ */
247
+
240
248
  Object.defineProperty(SchemaBoolean.prototype, '$conditionalHandlers', {
241
249
  enumerable: false,
242
250
  value: $conditionalHandlers
@@ -271,6 +271,14 @@ const $conditionalHandlers = {
271
271
  $lte: handleSingle
272
272
  };
273
273
 
274
+ /**
275
+ * Contains the handlers for different query operators for this schema type.
276
+ * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
277
+ *
278
+ * @property $conditionalHandlers
279
+ * @api public
280
+ */
281
+
274
282
  Object.defineProperty(SchemaBuffer.prototype, '$conditionalHandlers', {
275
283
  enumerable: false,
276
284
  value: $conditionalHandlers
@@ -397,6 +397,14 @@ const $conditionalHandlers = {
397
397
  $lte: handleSingle
398
398
  };
399
399
 
400
+ /**
401
+ * Contains the handlers for different query operators for this schema type.
402
+ * For example, `$conditionalHandlers.$gte` is the function Mongoose calls to cast `$gte` filter operators.
403
+ *
404
+ * @property $conditionalHandlers
405
+ * @api public
406
+ */
407
+
400
408
  Object.defineProperty(SchemaDate.prototype, '$conditionalHandlers', {
401
409
  enumerable: false,
402
410
  value: $conditionalHandlers
@@ -222,6 +222,14 @@ const $conditionalHandlers = {
222
222
  $lte: handleSingle
223
223
  };
224
224
 
225
+ /**
226
+ * Contains the handlers for different query operators for this schema type.
227
+ * For example, `$conditionalHandlers.$lte` is the function Mongoose calls to cast `$lte` filter operators.
228
+ *
229
+ * @property $conditionalHandlers
230
+ * @api public
231
+ */
232
+
225
233
  Object.defineProperty(SchemaDecimal128.prototype, '$conditionalHandlers', {
226
234
  enumerable: false,
227
235
  value: $conditionalHandlers
@@ -116,7 +116,19 @@ SchemaDocumentArray.options = { castNonArrays: true };
116
116
  SchemaDocumentArray.prototype = Object.create(SchemaArray.prototype);
117
117
  SchemaDocumentArray.prototype.constructor = SchemaDocumentArray;
118
118
  SchemaDocumentArray.prototype.OptionsConstructor = SchemaDocumentArrayOptions;
119
- SchemaDocumentArray.prototype.$conditionalHandlers = { ...SchemaArray.prototype.$conditionalHandlers };
119
+
120
+ /**
121
+ * Contains the handlers for different query operators for this schema type.
122
+ * For example, `$conditionalHandlers.$size` is the function Mongoose calls to cast `$size` filter operators.
123
+ *
124
+ * @property $conditionalHandlers
125
+ * @api public
126
+ */
127
+
128
+ Object.defineProperty(SchemaDocumentArray.prototype, '$conditionalHandlers', {
129
+ enumerable: false,
130
+ value: { ...SchemaArray.prototype.$conditionalHandlers }
131
+ });
120
132
 
121
133
  /*!
122
134
  * ignore
@@ -205,6 +205,14 @@ const $conditionalHandlers = {
205
205
  $lte: handleSingle
206
206
  };
207
207
 
208
+ /**
209
+ * Contains the handlers for different query operators for this schema type.
210
+ * For example, `$conditionalHandlers.$lt` is the function Mongoose calls to cast `$lt` filter operators.
211
+ *
212
+ * @property $conditionalHandlers
213
+ * @api public
214
+ */
215
+
208
216
  Object.defineProperty(SchemaDouble.prototype, '$conditionalHandlers', {
209
217
  enumerable: false,
210
218
  value: $conditionalHandlers
@@ -209,6 +209,14 @@ const $conditionalHandlers = {
209
209
  $bitsAnySet: handleBitwiseOperator
210
210
  };
211
211
 
212
+ /**
213
+ * Contains the handlers for different query operators for this schema type.
214
+ * For example, `$conditionalHandlers.$gt` is the function Mongoose calls to cast `$gt` filter operators.
215
+ *
216
+ * @property $conditionalHandlers
217
+ * @api public
218
+ */
219
+
212
220
  Object.defineProperty(SchemaInt32.prototype, '$conditionalHandlers', {
213
221
  enumerable: false,
214
222
  value: $conditionalHandlers
@@ -413,6 +413,14 @@ const $conditionalHandlers = {
413
413
  $mod: handleArray
414
414
  };
415
415
 
416
+ /**
417
+ * Contains the handlers for different query operators for this schema type.
418
+ * For example, `$conditionalHandlers.$gte` is the function Mongoose calls to cast `$gte` filter operators.
419
+ *
420
+ * @property $conditionalHandlers
421
+ * @api public
422
+ */
423
+
416
424
  Object.defineProperty(SchemaNumber.prototype, '$conditionalHandlers', {
417
425
  enumerable: false,
418
426
  value: $conditionalHandlers
@@ -268,6 +268,14 @@ const $conditionalHandlers = {
268
268
  $lte: handleSingle
269
269
  };
270
270
 
271
+ /**
272
+ * Contains the handlers for different query operators for this schema type.
273
+ * For example, `$conditionalHandlers.$in` is the function Mongoose calls to cast `$in` filter operators.
274
+ *
275
+ * @property $conditionalHandlers
276
+ * @api public
277
+ */
278
+
271
279
  Object.defineProperty(SchemaObjectId.prototype, '$conditionalHandlers', {
272
280
  enumerable: false,
273
281
  value: $conditionalHandlers
@@ -660,6 +660,14 @@ const $conditionalHandlers = {
660
660
  $not: handleSingle
661
661
  };
662
662
 
663
+ /**
664
+ * Contains the handlers for different query operators for this schema type.
665
+ * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
666
+ *
667
+ * @property $conditionalHandlers
668
+ * @api public
669
+ */
670
+
663
671
  Object.defineProperty(SchemaString.prototype, '$conditionalHandlers', {
664
672
  enumerable: false,
665
673
  value: $conditionalHandlers
@@ -117,6 +117,11 @@ function _createConstructor(schema, baseClass, options) {
117
117
  return _embedded;
118
118
  }
119
119
 
120
+ /*!
121
+ * ignore
122
+ */
123
+ const $conditionalHandlers = { ...SchemaType.prototype.$conditionalHandlers };
124
+
120
125
  /**
121
126
  * Special case for when users use a common location schema to represent
122
127
  * locations for use with $geoWithin.
@@ -126,7 +131,7 @@ function _createConstructor(schema, baseClass, options) {
126
131
  * @api private
127
132
  */
128
133
 
129
- SchemaSubdocument.prototype.$conditionalHandlers.$geoWithin = function handle$geoWithin(val, context) {
134
+ $conditionalHandlers.$geoWithin = function handle$geoWithin(val, context) {
130
135
  return { $geometry: this.castForQuery(null, val.$geometry, context) };
131
136
  };
132
137
 
@@ -134,19 +139,32 @@ SchemaSubdocument.prototype.$conditionalHandlers.$geoWithin = function handle$ge
134
139
  * ignore
135
140
  */
136
141
 
137
- SchemaSubdocument.prototype.$conditionalHandlers.$near =
138
- SchemaSubdocument.prototype.$conditionalHandlers.$nearSphere = geospatial.cast$near;
142
+ $conditionalHandlers.$near =
143
+ $conditionalHandlers.$nearSphere = geospatial.cast$near;
139
144
 
140
- SchemaSubdocument.prototype.$conditionalHandlers.$within =
141
- SchemaSubdocument.prototype.$conditionalHandlers.$geoWithin = geospatial.cast$within;
145
+ $conditionalHandlers.$within =
146
+ $conditionalHandlers.$geoWithin = geospatial.cast$within;
142
147
 
143
- SchemaSubdocument.prototype.$conditionalHandlers.$geoIntersects =
148
+ $conditionalHandlers.$geoIntersects =
144
149
  geospatial.cast$geoIntersects;
145
150
 
146
- SchemaSubdocument.prototype.$conditionalHandlers.$minDistance = castToNumber;
147
- SchemaSubdocument.prototype.$conditionalHandlers.$maxDistance = castToNumber;
151
+ $conditionalHandlers.$minDistance = castToNumber;
152
+ $conditionalHandlers.$maxDistance = castToNumber;
153
+
154
+ $conditionalHandlers.$exists = $exists;
155
+
156
+ /**
157
+ * Contains the handlers for different query operators for this schema type.
158
+ * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
159
+ *
160
+ * @property $conditionalHandlers
161
+ * @api public
162
+ */
148
163
 
149
- SchemaSubdocument.prototype.$conditionalHandlers.$exists = $exists;
164
+ Object.defineProperty(SchemaSubdocument.prototype, '$conditionalHandlers', {
165
+ enumerable: false,
166
+ value: $conditionalHandlers
167
+ });
150
168
 
151
169
  /**
152
170
  * Casts contents
@@ -258,6 +258,14 @@ const $conditionalHandlers = {
258
258
  $nin: handleArray
259
259
  };
260
260
 
261
+ /**
262
+ * Contains the handlers for different query operators for this schema type.
263
+ * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
264
+ *
265
+ * @property $conditionalHandlers
266
+ * @api public
267
+ */
268
+
261
269
  Object.defineProperty(SchemaUUID.prototype, '$conditionalHandlers', {
262
270
  enumerable: false,
263
271
  value: $conditionalHandlers
package/lib/schemaType.js CHANGED
@@ -1638,8 +1638,12 @@ function handle$in(val, context) {
1638
1638
  });
1639
1639
  }
1640
1640
 
1641
- /*!
1642
- * ignore
1641
+ /**
1642
+ * Contains the handlers for different query operators for this schema type.
1643
+ * For example, `$conditionalHandlers.$exists` is the function Mongoose calls to cast `$exists` filter operators.
1644
+ *
1645
+ * @property $conditionalHandlers
1646
+ * @api public
1643
1647
  */
1644
1648
 
1645
1649
  SchemaType.prototype.$conditionalHandlers = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.16.5",
4
+ "version": "8.17.0",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "bson": "^6.10.4",
24
24
  "kareem": "2.6.3",
25
- "mongodb": "~6.17.0",
25
+ "mongodb": "~6.18.0",
26
26
  "mpath": "0.9.0",
27
27
  "mquery": "5.0.0",
28
28
  "ms": "2.1.3",
@@ -4,7 +4,7 @@ declare module 'mongoose' {
4
4
  /** Extract generic type from Aggregate class */
5
5
  type AggregateExtract<P> = P extends Aggregate<infer T> ? T : never;
6
6
 
7
- interface AggregateOptions extends Omit<mongodb.AggregateOptions, 'session'>, SessionOption {
7
+ interface AggregateOptions extends Omit<mongodb.AggregateOptions & mongodb.Abortable, 'session'>, SessionOption {
8
8
  [key: string]: any;
9
9
  }
10
10
 
@@ -21,6 +21,8 @@ declare module 'mongoose' {
21
21
  name: string;
22
22
  }
23
23
 
24
+ export type BaseCollection<T extends mongodb.Document> = CollectionBase<T>;
25
+
24
26
  /*
25
27
  * section drivers/node-mongodb-native/collection.js
26
28
  */
@@ -71,6 +71,8 @@ declare module 'mongoose' {
71
71
  };
72
72
  }[keyof SchemaMap];
73
73
 
74
+ export type BaseConnection = Connection;
75
+
74
76
  class Connection extends events.EventEmitter implements SessionStarter {
75
77
  /** Runs a [db-level aggregate()](https://www.mongodb.com/docs/manual/reference/method/db.aggregate/) on this connection's underlying `db` */
76
78
  aggregate<ResultType = unknown>(pipeline?: PipelineStage[] | null, options?: AggregateOptions): Aggregate<Array<ResultType>>;
@@ -18,7 +18,7 @@ declare module 'mongoose' {
18
18
  * * TQueryHelpers - Object with any helpers that should be mixed into the Query type
19
19
  * * DocType - the type of the actual Document created
20
20
  */
21
- class Document<T = unknown, TQueryHelpers = any, DocType = any, TVirtuals = Record<string, any>> {
21
+ class Document<T = unknown, TQueryHelpers = any, DocType = any, TVirtuals = Record<string, any>, TSchemaOptions = {}> {
22
22
  constructor(doc?: any);
23
23
 
24
24
  /** This documents _id. */
@@ -256,23 +256,23 @@ declare module 'mongoose' {
256
256
  set(value: string | Record<string, any>): this;
257
257
 
258
258
  /** The return value of this method is used in calls to JSON.stringify(doc). */
259
- toJSON(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>>;
260
- toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>>>;
261
- toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>>>;
262
- toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>>>>;
263
- toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>>;
264
- toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>>>;
265
-
266
- toJSON<T = Default__v<Require_id<DocType>>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
267
- toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
268
- toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<T>>;
269
- toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenMaps: false }): T;
270
- toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<T>;
259
+ toJSON(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, TSchemaOptions>;
260
+ toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>;
261
+ toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>;
262
+ toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>, TSchemaOptions>>>;
263
+ toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>, TSchemaOptions>;
264
+ toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>, TSchemaOptions>>;
265
+
266
+ toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
267
+ toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
268
+ toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<T>>;
269
+ toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenMaps: false }): T;
270
+ toJSON<T = Default__v<Require_id<DocType>, TSchemaOptions>>(options: ToObjectOptions & { flattenMaps: false, flattenObjectIds: true }): ObjectIdToString<T>;
271
271
 
272
272
  /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
273
- toObject(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>>;
274
- toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>>;
275
- toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>>;
273
+ toObject(options: ToObjectOptions & { virtuals: true }): Default__v<Require_id<DocType & TVirtuals>, TSchemaOptions>;
274
+ toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>, TSchemaOptions>;
275
+ toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>, TSchemaOptions>;
276
276
 
277
277
  /** Clears the modified state on the specified path. */
278
278
  unmarkModified<T extends keyof DocType>(path: T): void;
package/types/index.d.ts CHANGED
@@ -91,7 +91,8 @@ declare module 'mongoose' {
91
91
  InferSchemaType<TSchema>,
92
92
  ObtainSchemaGeneric<TSchema, 'TVirtuals'> & ObtainSchemaGeneric<TSchema, 'TInstanceMethods'>,
93
93
  ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
94
- ObtainSchemaGeneric<TSchema, 'TVirtuals'>
94
+ ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
95
+ ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>
95
96
  >,
96
97
  TSchema
97
98
  > & ObtainSchemaGeneric<TSchema, 'TStaticMethods'>;
@@ -139,7 +140,7 @@ declare module 'mongoose' {
139
140
  ? IfAny<U, T & { _id: Types.ObjectId }, T & Required<{ _id: U }>>
140
141
  : T & { _id: Types.ObjectId };
141
142
 
142
- export type Default__v<T> = T extends { __v?: infer U }
143
+ export type Default__v<T, TSchemaOptions = {}> = TSchemaOptions extends { versionKey: false } ? T : T extends { __v?: infer U }
143
144
  ? T
144
145
  : T & { __v: number };
145
146
 
@@ -148,17 +149,18 @@ declare module 'mongoose' {
148
149
  DocType,
149
150
  TOverrides = {},
150
151
  TQueryHelpers = {},
151
- TVirtuals = {}
152
+ TVirtuals = {},
153
+ TSchemaOptions = {}
152
154
  > = IfAny<
153
155
  DocType,
154
156
  any,
155
157
  TOverrides extends Record<string, never> ?
156
- Document<unknown, TQueryHelpers, DocType, TVirtuals> & Default__v<Require_id<DocType>> :
158
+ Document<unknown, TQueryHelpers, DocType, TVirtuals, TSchemaOptions> & Default__v<Require_id<DocType>, TSchemaOptions> :
157
159
  IfAny<
158
160
  TOverrides,
159
- Document<unknown, TQueryHelpers, DocType, TVirtuals> & Default__v<Require_id<DocType>>,
160
- Document<unknown, TQueryHelpers, DocType, TVirtuals> & MergeType<
161
- Default__v<Require_id<DocType>>,
161
+ Document<unknown, TQueryHelpers, DocType, TVirtuals, TSchemaOptions> & Default__v<Require_id<DocType>, TSchemaOptions>,
162
+ Document<unknown, TQueryHelpers, DocType, TVirtuals, TSchemaOptions> & MergeType<
163
+ Default__v<Require_id<DocType>, TSchemaOptions>,
162
164
  TOverrides
163
165
  >
164
166
  >
@@ -196,10 +198,11 @@ declare module 'mongoose' {
196
198
  >;
197
199
 
198
200
  export type HydratedDocumentFromSchema<TSchema extends Schema> = HydratedDocument<
199
- InferSchemaType<TSchema>,
200
- ObtainSchemaGeneric<TSchema, 'TInstanceMethods'> & ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
201
- ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
202
- ObtainSchemaGeneric<TSchema, 'TVirtuals'>
201
+ InferSchemaType<TSchema>,
202
+ ObtainSchemaGeneric<TSchema, 'TInstanceMethods'> & ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
203
+ ObtainSchemaGeneric<TSchema, 'TQueryHelpers'>,
204
+ ObtainSchemaGeneric<TSchema, 'TVirtuals'>,
205
+ ObtainSchemaGeneric<TSchema, 'TSchemaOptions'>
203
206
  >;
204
207
 
205
208
  export interface TagSet {
@@ -272,7 +275,7 @@ declare module 'mongoose' {
272
275
  ObtainDocumentType<any, RawDocType, ResolveSchemaOptions<TSchemaOptions>>,
273
276
  ResolveSchemaOptions<TSchemaOptions>
274
277
  >,
275
- THydratedDocumentType = HydratedDocument<FlatRecord<DocType>, TVirtuals & TInstanceMethods, {}, TVirtuals>
278
+ THydratedDocumentType = HydratedDocument<FlatRecord<DocType>, TVirtuals & TInstanceMethods, {}, TVirtuals, ResolveSchemaOptions<TSchemaOptions>>
276
279
  >
277
280
  extends events.EventEmitter {
278
281
  /**
@@ -370,6 +373,8 @@ declare module 'mongoose' {
370
373
  /** Returns a new schema that has the `paths` from the original schema, minus the omitted ones. */
371
374
  omit<T = this>(paths: string[], options?: SchemaOptions): T;
372
375
 
376
+ options: SchemaOptions;
377
+
373
378
  /** Gets/sets schema paths. */
374
379
  path<ResultType extends SchemaType = SchemaType<any, THydratedDocumentType>>(path: string): ResultType;
375
380
  path<pathGeneric extends keyof RawDocType>(path: pathGeneric): SchemaType<RawDocType[pathGeneric]>;
@@ -602,7 +607,7 @@ declare module 'mongoose' {
602
607
  | typeof Schema.Types.UUID;
603
608
 
604
609
 
605
- export type InferId<T> = T extends { _id?: any } ? T['_id'] : Types.ObjectId;
610
+ export type InferId<T> = mongodb.InferIdType<T>;
606
611
 
607
612
  export interface VirtualTypeOptions<HydratedDocType = Document, DocType = unknown> {
608
613
  /** If `ref` is not nullish, this becomes a populated virtual. */
@@ -897,11 +902,6 @@ declare module 'mongoose' {
897
902
 
898
903
  export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
899
904
 
900
- /**
901
- * Helper to choose the best option between two type helpers
902
- */
903
- export type _pickObject<T1, T2, Fallback> = T1 extends false ? T2 extends false ? Fallback : T2 : T1;
904
-
905
905
  /* for ts-mongoose */
906
906
  export class mquery { }
907
907
 
package/types/models.d.ts CHANGED
@@ -273,7 +273,6 @@ declare module 'mongoose' {
273
273
  THydratedDocumentType = HydratedDocument<TRawDocType, TVirtuals & TInstanceMethods, TQueryHelpers, TVirtuals>,
274
274
  TSchema = any> extends
275
275
  NodeJS.EventEmitter,
276
- AcceptsDiscriminator,
277
276
  IndexManager,
278
277
  SessionStarter {
279
278
  new <DocType = Partial<TRawDocType>>(doc?: DocType, fields?: any | null, options?: boolean | AnyObject): THydratedDocumentType;
@@ -313,11 +312,11 @@ declare module 'mongoose' {
313
312
  * round trip to the MongoDB server.
314
313
  */
315
314
  bulkWrite<DocContents = TRawDocType>(
316
- writes: Array<AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
315
+ writes: Array<AnyBulkWriteOperation<DocContents>>,
317
316
  options: MongooseBulkWriteOptions & { ordered: false }
318
317
  ): Promise<MongooseBulkWriteResult>;
319
318
  bulkWrite<DocContents = TRawDocType>(
320
- writes: Array<AnyBulkWriteOperation<DocContents extends Document ? any : (DocContents extends {} ? DocContents : any)>>,
319
+ writes: Array<AnyBulkWriteOperation<DocContents>>,
321
320
  options?: MongooseBulkWriteOptions
322
321
  ): Promise<MongooseBulkWriteResult>;
323
322
 
@@ -334,7 +333,7 @@ declare module 'mongoose' {
334
333
  /** Creates a `countDocuments` query: counts the number of documents that match `filter`. */
335
334
  countDocuments(
336
335
  filter?: RootFilterQuery<TRawDocType>,
337
- options?: (mongodb.CountOptions & MongooseBaseQueryOptions<TRawDocType>) | null
336
+ options?: (mongodb.CountOptions & MongooseBaseQueryOptions<TRawDocType> & mongodb.Abortable) | null
338
337
  ): QueryWithHelpers<
339
338
  number,
340
339
  THydratedDocumentType,
@@ -426,6 +425,28 @@ declare module 'mongoose' {
426
425
  TInstanceMethods & TVirtuals
427
426
  >;
428
427
 
428
+ /** Adds a discriminator type. */
429
+ discriminator<TDiscriminatorSchema extends Schema<any, any>>(
430
+ name: string | number,
431
+ schema: TDiscriminatorSchema,
432
+ value?: string | number | ObjectId | DiscriminatorOptions
433
+ ): Model<
434
+ TRawDocType & InferSchemaType<TDiscriminatorSchema>,
435
+ TQueryHelpers & ObtainSchemaGeneric<TDiscriminatorSchema, 'TQueryHelpers'>,
436
+ TInstanceMethods & ObtainSchemaGeneric<TDiscriminatorSchema, 'TInstanceMethods'>,
437
+ TVirtuals & ObtainSchemaGeneric<TDiscriminatorSchema, 'TVirtuals'>
438
+ > & ObtainSchemaGeneric<TDiscriminatorSchema, 'TStaticMethods'>;
439
+ discriminator<D>(
440
+ name: string | number,
441
+ schema: Schema,
442
+ value?: string | number | ObjectId | DiscriminatorOptions
443
+ ): Model<D>;
444
+ discriminator<T, U>(
445
+ name: string | number,
446
+ schema: Schema<T, U>,
447
+ value?: string | number | ObjectId | DiscriminatorOptions
448
+ ): U;
449
+
429
450
  /**
430
451
  * Delete an existing [Atlas search index](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) by name.
431
452
  * This function only works when connected to MongoDB Atlas.
@@ -469,7 +490,7 @@ declare module 'mongoose' {
469
490
  findOne<ResultDoc = THydratedDocumentType>(
470
491
  filter: RootFilterQuery<TRawDocType>,
471
492
  projection: ProjectionType<TRawDocType> | null | undefined,
472
- options: QueryOptions<TRawDocType> & { lean: true }
493
+ options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
473
494
  ): QueryWithHelpers<
474
495
  GetLeanResultType<TRawDocType, TRawDocType, 'findOne'> | null,
475
496
  ResultDoc,
@@ -481,7 +502,7 @@ declare module 'mongoose' {
481
502
  findOne<ResultDoc = THydratedDocumentType>(
482
503
  filter?: RootFilterQuery<TRawDocType>,
483
504
  projection?: ProjectionType<TRawDocType> | null,
484
- options?: QueryOptions<TRawDocType> | null
505
+ options?: QueryOptions<TRawDocType> & mongodb.Abortable | null
485
506
  ): QueryWithHelpers<ResultDoc | null, ResultDoc, TQueryHelpers, TRawDocType, 'findOne', TInstanceMethods & TVirtuals>;
486
507
  findOne<ResultDoc = THydratedDocumentType>(
487
508
  filter?: RootFilterQuery<TRawDocType>,
@@ -700,7 +721,7 @@ declare module 'mongoose' {
700
721
  find<ResultDoc = THydratedDocumentType>(
701
722
  filter: RootFilterQuery<TRawDocType>,
702
723
  projection: ProjectionType<TRawDocType> | null | undefined,
703
- options: QueryOptions<TRawDocType> & { lean: true }
724
+ options: QueryOptions<TRawDocType> & { lean: true } & mongodb.Abortable
704
725
  ): QueryWithHelpers<
705
726
  GetLeanResultType<TRawDocType, TRawDocType[], 'find'>,
706
727
  ResultDoc,
@@ -712,7 +733,7 @@ declare module 'mongoose' {
712
733
  find<ResultDoc = THydratedDocumentType>(
713
734
  filter: RootFilterQuery<TRawDocType>,
714
735
  projection?: ProjectionType<TRawDocType> | null | undefined,
715
- options?: QueryOptions<TRawDocType> | null | undefined
736
+ options?: QueryOptions<TRawDocType> & mongodb.Abortable | null | undefined
716
737
  ): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, TRawDocType, 'find', TInstanceMethods & TVirtuals>;
717
738
  find<ResultDoc = THydratedDocumentType>(
718
739
  filter: RootFilterQuery<TRawDocType>,
@@ -885,7 +906,7 @@ declare module 'mongoose' {
885
906
  replaceOne<ResultDoc = THydratedDocumentType>(
886
907
  filter?: RootFilterQuery<TRawDocType>,
887
908
  replacement?: TRawDocType | AnyObject,
888
- options?: (mongodb.ReplaceOptions & MongooseQueryOptions<TRawDocType>) | null
909
+ options?: (mongodb.ReplaceOptions & QueryOptions<TRawDocType>) | null
889
910
  ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'replaceOne', TInstanceMethods & TVirtuals>;
890
911
 
891
912
  /** Apply changes made to this model's schema after this model was compiled. */