mongoose 8.9.7 → 8.10.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "8.9.7",
4
+ "version": "8.10.0",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -17,11 +17,12 @@
17
17
  "orm",
18
18
  "db"
19
19
  ],
20
+ "type": "commonjs",
20
21
  "license": "MIT",
21
22
  "dependencies": {
22
23
  "bson": "^6.10.1",
23
24
  "kareem": "2.6.3",
24
- "mongodb": "~6.12.0",
25
+ "mongodb": "~6.13.0",
25
26
  "mpath": "0.9.0",
26
27
  "mquery": "5.0.0",
27
28
  "ms": "2.1.3",
@@ -35,6 +36,7 @@
35
36
  "acquit": "1.3.0",
36
37
  "acquit-ignore": "0.2.1",
37
38
  "acquit-require": "0.1.1",
39
+ "ajv": "8.17.1",
38
40
  "assert-browserify": "2.0.0",
39
41
  "babel-loader": "8.2.5",
40
42
  "broken-link-checker": "^0.7.8",
@@ -102,6 +104,8 @@
102
104
  "test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
103
105
  "test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
104
106
  "test-tsd": "node ./test/types/check-types-filename && tsd",
107
+ "setup-test-encryption": "bash scripts/configure-cluster-with-encryption.sh",
108
+ "test-encryption": "mocha --exit ./test/encryption/*.test.js",
105
109
  "tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
106
110
  "test-coverage": "nyc --reporter=html --reporter=text npm test",
107
111
  "ts-benchmark": "cd ./benchmarks/typescript/simple && npm install && npm run benchmark | node ../../../scripts/tsc-diagnostics-check"
@@ -59,6 +59,8 @@ declare module 'mongoose' {
59
59
  }
60
60
 
61
61
  class Connection extends events.EventEmitter implements SessionStarter {
62
+ aggregate<ResultType = unknown>(pipeline?: PipelineStage[] | null, options?: AggregateOptions): Aggregate<Array<ResultType>>;
63
+
62
64
  /** Returns a promise that resolves when this connection successfully connects to MongoDB */
63
65
  asPromise(): Promise<this>;
64
66
 
@@ -256,21 +256,21 @@ 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 & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Require_id<DocType>>;
260
- toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Require_id<DocType>>;
261
- toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Require_id<DocType>>>;
262
- toJSON(options: ToObjectOptions & { flattenMaps: false }): Require_id<DocType>;
263
- toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Require_id<DocType>>;
264
-
265
- toJSON<T = Require_id<DocType>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
266
- toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
267
- toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<T>>;
268
- toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenMaps: false }): T;
269
- toJSON<T = Require_id<DocType>>(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<T>;
259
+ toJSON(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<Default__v<Require_id<DocType>>>;
260
+ toJSON(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<Default__v<Require_id<DocType>>>;
261
+ toJSON(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<Default__v<Require_id<DocType>>>>;
262
+ toJSON(options: ToObjectOptions & { flattenMaps: false }): Default__v<Require_id<DocType>>;
263
+ toJSON(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<Default__v<Require_id<DocType>>>;
264
+
265
+ toJSON<T = Default__v<Require_id<DocType>>>(options?: ToObjectOptions & { flattenMaps?: true, flattenObjectIds?: false }): FlattenMaps<T>;
266
+ toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenObjectIds: false }): FlattenMaps<T>;
267
+ toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenObjectIds: true }): ObjectIdToString<FlattenMaps<T>>;
268
+ toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenMaps: false }): T;
269
+ toJSON<T = Default__v<Require_id<DocType>>>(options: ToObjectOptions & { flattenMaps: false; flattenObjectIds: true }): ObjectIdToString<T>;
270
270
 
271
271
  /** Converts this document into a plain-old JavaScript object ([POJO](https://masteringjs.io/tutorials/fundamentals/pojo)). */
272
- toObject(options?: ToObjectOptions): Require_id<DocType>;
273
- toObject<T>(options?: ToObjectOptions): Require_id<T>;
272
+ toObject(options?: ToObjectOptions): Default__v<Require_id<DocType>>;
273
+ toObject<T>(options?: ToObjectOptions): Default__v<Require_id<T>>;
274
274
 
275
275
  /** Clears the modified state on the specified path. */
276
276
  unmarkModified<T extends keyof DocType>(path: T): void;
package/types/index.d.ts CHANGED
@@ -508,6 +508,8 @@ declare module 'mongoose' {
508
508
  statics: { [F in keyof TStaticMethods]: TStaticMethods[F] } &
509
509
  { [name: string]: (this: TModelType, ...args: any[]) => unknown };
510
510
 
511
+ toJSONSchema(options?: { useBsonType?: boolean }): Record<string, any>;
512
+
511
513
  /** Creates a virtual type with the given name. */
512
514
  virtual<T = HydratedDocument<DocType, TVirtuals & TInstanceMethods, TQueryHelpers>>(
513
515
  name: keyof TVirtuals | string,
@@ -827,7 +829,7 @@ declare module 'mongoose' {
827
829
  ? Types.DocumentArray<FlattenMaps<ItemType>> : FlattenMaps<T>;
828
830
 
829
831
  export type actualPrimitives = string | boolean | number | bigint | symbol | null | undefined;
830
- export type TreatAsPrimitives = actualPrimitives | NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId | Buffer | Function | mongodb.Binary;
832
+ export type TreatAsPrimitives = actualPrimitives | NativeDate | RegExp | symbol | Error | BigInt | Types.ObjectId | Buffer | Function | mongodb.Binary | mongodb.ClientSession;
831
833
 
832
834
  export type SchemaDefinitionType<T> = T extends Document ? Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>> : T;
833
835
 
package/types/models.d.ts CHANGED
@@ -577,6 +577,13 @@ declare module 'mongoose' {
577
577
  Array<MergeType<THydratedDocumentType, Omit<DocContents, '_id'>>>
578
578
  >;
579
579
 
580
+ /**
581
+ * Shortcut for saving one document to the database.
582
+ * `MyModel.insertOne(obj, options)` is almost equivalent to `new MyModel(obj).save(options)`.
583
+ * The difference is that `insertOne()` checks if `obj` is already a document, and checks for discriminators.
584
+ */
585
+ insertOne<DocContents = AnyKeys<TRawDocType>>(doc: DocContents | TRawDocType, options?: SaveOptions): Promise<THydratedDocumentType>;
586
+
580
587
  /**
581
588
  * List all [Atlas search indexes](https://www.mongodb.com/docs/atlas/atlas-search/create-index/) on this model's collection.
582
589
  * This function only works when connected to MongoDB Atlas.
@@ -608,6 +615,13 @@ declare module 'mongoose' {
608
615
  */
609
616
  updateSearchIndex(name: string, definition: AnyObject): Promise<void>;
610
617
 
618
+ /**
619
+ * Changes the Connection instance this model uses to make requests to MongoDB.
620
+ * This function is most useful for changing the Connection that a Model defined using `mongoose.model()` uses
621
+ * after initialization.
622
+ */
623
+ useConnection(connection: Connection): this;
624
+
611
625
  /** Casts and validates the given object against this model's schema, passing the given `context` to custom validators. */
612
626
  validate(): Promise<void>;
613
627
  validate(obj: any): Promise<void>;
@@ -869,17 +883,20 @@ declare module 'mongoose' {
869
883
 
870
884
  /** Creates a `updateMany` query: updates all documents that match `filter` with `update`. */
871
885
  updateMany<ResultDoc = THydratedDocumentType>(
872
- filter?: RootFilterQuery<TRawDocType>,
873
- update?: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
886
+ filter: RootFilterQuery<TRawDocType>,
887
+ update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
874
888
  options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
875
889
  ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateMany', TInstanceMethods & TVirtuals>;
876
890
 
877
891
  /** Creates a `updateOne` query: updates the first document that matches `filter` with `update`. */
878
892
  updateOne<ResultDoc = THydratedDocumentType>(
879
- filter?: RootFilterQuery<TRawDocType>,
880
- update?: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
893
+ filter: RootFilterQuery<TRawDocType>,
894
+ update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline,
881
895
  options?: (mongodb.UpdateOptions & MongooseUpdateQueryOptions<TRawDocType>) | null
882
896
  ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateOne', TInstanceMethods & TVirtuals>;
897
+ updateOne<ResultDoc = THydratedDocumentType>(
898
+ update: UpdateQuery<TRawDocType> | UpdateWithAggregationPipeline
899
+ ): QueryWithHelpers<UpdateWriteOpResult, ResultDoc, TQueryHelpers, TRawDocType, 'updateOne', TInstanceMethods & TVirtuals>;
883
900
 
884
901
  /** Creates a Query, applies the passed conditions, and returns the Query. */
885
902
  where<ResultDoc = THydratedDocumentType>(
package/types/query.d.ts CHANGED
@@ -850,20 +850,26 @@ declare module 'mongoose' {
850
850
  * the `multi` option.
851
851
  */
852
852
  updateMany(
853
- filter?: RootFilterQuery<RawDocType>,
854
- update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
853
+ filter: RootFilterQuery<RawDocType>,
854
+ update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
855
855
  options?: QueryOptions<DocType> | null
856
856
  ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
857
+ updateMany(
858
+ update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline
859
+ ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateMany', TDocOverrides>;
857
860
 
858
861
  /**
859
862
  * Declare and/or execute this query as an updateOne() operation. Same as
860
863
  * `update()`, except it does not support the `multi` or `overwrite` options.
861
864
  */
862
865
  updateOne(
863
- filter?: RootFilterQuery<RawDocType>,
864
- update?: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
866
+ filter: RootFilterQuery<RawDocType>,
867
+ update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline,
865
868
  options?: QueryOptions<DocType> | null
866
869
  ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
870
+ updateOne(
871
+ update: UpdateQuery<RawDocType> | UpdateWithAggregationPipeline
872
+ ): QueryWithHelpers<UpdateWriteOpResult, DocType, THelpers, RawDocType, 'updateOne', TDocOverrides>;
867
873
 
868
874
  /**
869
875
  * Sets the specified number of `mongod` servers, or tag set of `mongod` servers,
@@ -300,6 +300,8 @@ declare module 'mongoose' {
300
300
  /** Declares a full text index. */
301
301
  text(bool: boolean): this;
302
302
 
303
+ toJSONSchema(options?: { useBsonType?: boolean }): Record<string, any>;
304
+
303
305
  /** Defines a custom function for transforming this path when converting a document to JSON. */
304
306
  transform(fn: (value: any) => any): this;
305
307