mongoose 5.11.4 → 5.11.8
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/History.md +44 -0
- package/dist/browser.umd.js +1 -1
- package/index.d.ts +155 -28
- package/lib/model.js +7 -3
- package/lib/schema/map.js +14 -2
- package/package.json +4 -4
package/History.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
5.11.8 / 2020-12-14
|
|
2
|
+
===================
|
|
3
|
+
* fix(index.d.ts): add missing single document populate #9696 [YC](https://github.com/YC)
|
|
4
|
+
* fix(index.d.ts): make options optional for `toObject` #9700
|
|
5
|
+
* fix(index.d.ts): added missing match and model methods in Aggregate class #9710 [manekshms](https://github.com/manekshms)
|
|
6
|
+
* fix(index.d.ts): make options optional for `createIndexes()` and `ensureIndexes()` #9706
|
|
7
|
+
* fix(index.d.ts): support passing a function to `ValidateOpts.message` #9697
|
|
8
|
+
* docs: add media query for ::before on headings #9705 #9704 [YC](https://github.com/YC)
|
|
9
|
+
|
|
10
|
+
5.11.7 / 2020-12-10
|
|
11
|
+
===================
|
|
12
|
+
* fix(document): ensure calling `get()` with empty string returns undefined for mongoose-plugin-autoinc #9681
|
|
13
|
+
* fix(model): set `isNew` to false for documents that were successfully inserted by `insertMany` with `ordered = false` when an error occurred #9677
|
|
14
|
+
* fix(index.d.ts): add missing Aggregate#skip() & Aggregate#limit() #9692 [sahasayan](https://github.com/sahasayan)
|
|
15
|
+
* fix(index.d.ts): make `Document#id` optional so types that use `id` can use `Model<IMyType & Document>` #9684
|
|
16
|
+
|
|
17
|
+
5.11.6 / 2020-12-09
|
|
18
|
+
===================
|
|
19
|
+
* fix(middleware): ensure sync errors in pre hooks always bubble up to the calling code #9659
|
|
20
|
+
* fix(index.d.ts): allow passing ObjectId properties as strings to `create()` and `findOneAndReplace()` #9676
|
|
21
|
+
* fix(index.d.ts): allow calling `mongoose.model()` and `Connection#model()` with model as generic param #9685 #9678 [sahasayan](https://github.com/sahasayan)
|
|
22
|
+
* fix(index.d.ts): Fix return type of Model#aggregate() #9680 [orgads](https://github.com/orgads)
|
|
23
|
+
* fix(index.d.ts): optional next() parameter for post middleware #9683 [isengartz](https://github.com/isengartz)
|
|
24
|
+
* fix(index.d.ts): allow array of validators in SchemaTypeOptions #9686 [cjroebuck](https://github.com/cjroebuck)
|
|
25
|
+
|
|
26
|
+
5.11.5 / 2020-12-07
|
|
27
|
+
===================
|
|
28
|
+
* fix(map): support `null` in maps of subdocs #9628
|
|
29
|
+
* fix(index.d.ts): support object syntax for `validate` #9667
|
|
30
|
+
* fix(index.d.ts): Allow number for Schema expires #9670 [alecgibson](https://github.com/alecgibson)
|
|
31
|
+
* fix(index.d.ts): allow definining arbitrary properties on SchemaTypeOpts for plugins like mongoose-autopopulate #9669
|
|
32
|
+
* fix(index.d.ts): add mongoose.models #9661 #9660 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
|
33
|
+
* fix(index.d.ts): allow the next() argument to be optional #9665 #9664 [sahasayan](https://github.com/sahasayan)
|
|
34
|
+
* fix(index.d.ts): add missing `VirtualType#applyGetters()` and `applySetters()`, `Schema#virtuals`, `Schema#childSchemas`, `Query#_mongooseOptions` #9658
|
|
35
|
+
* fix(index.d.ts): add `id` to LeanDocuments in case it is defined in the user's schema #9657
|
|
36
|
+
* fix(index.d.ts): add missing types for hook functions #9653
|
|
37
|
+
* fix(index.d.ts): improve support for strict null checks with `upsert` and `orFail()` #9654
|
|
38
|
+
* fix(index.d.ts): make return values for `insertMany()` more consistent #9662
|
|
39
|
+
* fix(index.d.ts): Change options in Connection#collection() to be optional #9663 [orgads](https://github.com/orgads)
|
|
40
|
+
* fix(index.d.ts): add the missing generic declaration for Schema #9655 [sahasayan](https://github.com/sahasayan)
|
|
41
|
+
* fix(index.d.ts): add missing `SchemaTypeOpts` and `ConnectionOptions` aliases for backwards compat
|
|
42
|
+
* docs(populate): remove `sort()` from `limit` example to avoid potential confusion #9584
|
|
43
|
+
* docs(compatibility): add MongoDB server 4.4 version compatibility #9641
|
|
44
|
+
|
|
1
45
|
5.11.4 / 2020-12-04
|
|
2
46
|
===================
|
|
3
47
|
* fix(index.d.ts): add `Document#__v` so documents have a Version by default #9652 [sahasayan](https://github.com/sahasayan)
|
package/dist/browser.umd.js
CHANGED
|
@@ -1517,7 +1517,7 @@ t.exports=l}).call(this,r(1).Buffer)},function(t,e,r){"use strict";(function(e){
|
|
|
1517
1517
|
/*!
|
|
1518
1518
|
* ignore
|
|
1519
1519
|
*/
|
|
1520
|
-
function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return(a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=f(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=f(t);if(e){var o=f(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function l(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=r(87),h=r(171),y=r(7),d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(h,t);var r,n,i,l=c(h);function h(t,e){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,h),(r=l.call(this,t,e,"Map")).$isSchemaMap=!0,r}return r=h,(n=[{key:"set",value:function(t,e){return y.set(t,e)}},{key:"cast",value:function(t,r,n){if(t instanceof p)return t;if(n){var i=new p({},this.path,r,this.$__schemaType);if(t instanceof e.Map){var s,a=o(t.keys());try{for(a.s();!(s=a.n()).done;){var u=s.value;i.$
|
|
1520
|
+
function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return(a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=f(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=f(t);if(e){var o=f(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function l(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=r(87),h=r(171),y=r(7),d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(h,t);var r,n,i,l=c(h);function h(t,e){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,h),(r=l.call(this,t,e,"Map")).$isSchemaMap=!0,r}return r=h,(n=[{key:"set",value:function(t,e){return y.set(t,e)}},{key:"cast",value:function(t,r,n){if(t instanceof p)return t;if(n){var i=new p({},this.path,r,this.$__schemaType);if(t instanceof e.Map){var s,a=o(t.keys());try{for(a.s();!(s=a.n()).done;){var u=s.value,c=t.get(u);c=null==c?i.$__schemaType._castNullish(c):i.$__schemaType.cast(c,r,!0),i.$init(u,c)}}catch(t){a.e(t)}finally{a.f()}}else for(var l=0,f=Object.keys(t);l<f.length;l++){var h=f[l],y=t[h];y=null==y?i.$__schemaType._castNullish(y):i.$__schemaType.cast(y,r,!0),i.$init(h,y)}return i}return new p(t,this.path,r,this.$__schemaType)}},{key:"clone",value:function(){var t=a(f(h.prototype),"clone",this).call(this);return null!=this.$__schemaType&&(t.$__schemaType=this.$__schemaType.clone()),t}}])&&s(r.prototype,n),i&&s(r,i),h}(y);d.prototype.OptionsConstructor=h,d.defaultOptions={},t.exports=d}).call(this,r(11))},function(t,e,r){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u(t);if(e){var o=u(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return a(this,r)}}function a(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var c=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}(r,t);var e=s(r);function r(){return o(this,r),e.apply(this,arguments)}return r}(r(9)),l=r(10);Object.defineProperty(c.prototype,"of",l),t.exports=c},function(t,e,r){"use strict";(function(t){
|
|
1521
1521
|
/*!
|
|
1522
1522
|
* Module dependencies.
|
|
1523
1523
|
*/
|
package/index.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ declare module "mongoose" {
|
|
|
72
72
|
/** An array containing all connections associated with this Mongoose instance. */
|
|
73
73
|
export var connections: Connection[];
|
|
74
74
|
|
|
75
|
+
/** An array containing all models associated with this Mongoose instance. */
|
|
76
|
+
export var models: { [index: string]: Model<any> };
|
|
75
77
|
/** Creates a Connection instance. */
|
|
76
78
|
export function createConnection(uri: string, options?: ConnectOptions): Connection & Promise<Connection>;
|
|
77
79
|
export function createConnection(): Connection;
|
|
@@ -97,6 +99,12 @@ declare module "mongoose" {
|
|
|
97
99
|
export function isValidObjectId(v: any): boolean;
|
|
98
100
|
|
|
99
101
|
export function model<T extends Document>(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model<T>;
|
|
102
|
+
export function model<T extends Document, U extends Model<T>>(
|
|
103
|
+
name: string,
|
|
104
|
+
schema?: Schema,
|
|
105
|
+
collection?: string,
|
|
106
|
+
skipInit?: boolean
|
|
107
|
+
): U;
|
|
100
108
|
|
|
101
109
|
/** Returns an array of model names created on this instance of Mongoose. */
|
|
102
110
|
export function modelNames(): Array<string>;
|
|
@@ -163,7 +171,7 @@ declare module "mongoose" {
|
|
|
163
171
|
close(force?: boolean): Promise<void>;
|
|
164
172
|
|
|
165
173
|
/** Retrieves a collection, creating it if not cached. */
|
|
166
|
-
collection(name: string, options
|
|
174
|
+
collection(name: string, options?: mongodb.CollectionCreateOptions): Collection;
|
|
167
175
|
|
|
168
176
|
/** A hash of the collections associated with this connection */
|
|
169
177
|
collections: { [index: string]: Collection };
|
|
@@ -234,6 +242,12 @@ declare module "mongoose" {
|
|
|
234
242
|
|
|
235
243
|
/** Defines or retrieves a model. */
|
|
236
244
|
model<T extends Document>(name: string, schema?: Schema, collection?: string): Model<T>;
|
|
245
|
+
model<T extends Document, U extends Model<T>>(
|
|
246
|
+
name: string,
|
|
247
|
+
schema?: Schema,
|
|
248
|
+
collection?: string,
|
|
249
|
+
skipInit?: boolean
|
|
250
|
+
): U;
|
|
237
251
|
|
|
238
252
|
/** Returns an array of model names created on this connection. */
|
|
239
253
|
modelNames(): Array<string>;
|
|
@@ -349,11 +363,11 @@ declare module "mongoose" {
|
|
|
349
363
|
getIndexes(): any;
|
|
350
364
|
}
|
|
351
365
|
|
|
352
|
-
class Document {
|
|
366
|
+
class Document<T = any> {
|
|
353
367
|
constructor(doc?: any);
|
|
354
368
|
|
|
355
369
|
/** This documents _id. */
|
|
356
|
-
_id?:
|
|
370
|
+
_id?: T;
|
|
357
371
|
|
|
358
372
|
/** This documents __v. */
|
|
359
373
|
__v?: number;
|
|
@@ -442,7 +456,7 @@ declare module "mongoose" {
|
|
|
442
456
|
* document has an `_id`, in which case this function falls back to using
|
|
443
457
|
* `deepEqual()`.
|
|
444
458
|
*/
|
|
445
|
-
equals(doc: Document): boolean;
|
|
459
|
+
equals(doc: Document<T>): boolean;
|
|
446
460
|
|
|
447
461
|
/** Hash containing current validation errors. */
|
|
448
462
|
errors?: Error.ValidationError;
|
|
@@ -461,7 +475,7 @@ declare module "mongoose" {
|
|
|
461
475
|
getChanges(): UpdateQuery<this>;
|
|
462
476
|
|
|
463
477
|
/** The string version of this documents _id. */
|
|
464
|
-
id
|
|
478
|
+
id?: string;
|
|
465
479
|
|
|
466
480
|
/** Signal that we desire an increment of this documents version. */
|
|
467
481
|
increment(): this;
|
|
@@ -576,8 +590,8 @@ declare module "mongoose" {
|
|
|
576
590
|
interface Model<T extends Document> extends NodeJS.EventEmitter {
|
|
577
591
|
new(doc?: any): T;
|
|
578
592
|
|
|
579
|
-
aggregate<R>(pipeline?: any[]): Aggregate<Array<R>>;
|
|
580
|
-
aggregate<R>(pipeline: any[], cb: Function): Promise<Array<R>>;
|
|
593
|
+
aggregate<R = any>(pipeline?: any[]): Aggregate<Array<R>>;
|
|
594
|
+
aggregate<R = any>(pipeline: any[], cb: Function): Promise<Array<R>>;
|
|
581
595
|
|
|
582
596
|
/** Base Mongoose instance the model uses. */
|
|
583
597
|
base: typeof mongoose;
|
|
@@ -628,8 +642,7 @@ declare module "mongoose" {
|
|
|
628
642
|
* Similar to `ensureIndexes()`, except for it uses the [`createIndex`](http://mongodb.github.io/node-mongodb-native/2.2/api/Collection.html#createIndex)
|
|
629
643
|
* function.
|
|
630
644
|
*/
|
|
631
|
-
createIndexes(options: any): Promise<void>;
|
|
632
|
-
createIndexes(options: any, callback?: (err: any) => void): Promise<void>;
|
|
645
|
+
createIndexes(options?: any, callback?: (err: any) => void): Promise<void>;
|
|
633
646
|
|
|
634
647
|
/** Connection the model uses. */
|
|
635
648
|
db: Connection;
|
|
@@ -652,8 +665,7 @@ declare module "mongoose" {
|
|
|
652
665
|
* Sends `createIndex` commands to mongo for each index declared in the schema.
|
|
653
666
|
* The `createIndex` commands are sent in series.
|
|
654
667
|
*/
|
|
655
|
-
ensureIndexes(options: any): Promise<void>;
|
|
656
|
-
ensureIndexes(options: any, callback?: (err: any) => void): Promise<void>;
|
|
668
|
+
ensureIndexes(options?: any, callback?: (err: any) => void): Promise<void>;
|
|
657
669
|
|
|
658
670
|
/**
|
|
659
671
|
* Event emitter that reports any errors that occurred. Useful for global error
|
|
@@ -688,8 +700,10 @@ declare module "mongoose" {
|
|
|
688
700
|
init(callback?: (err: any) => void): Promise<T>;
|
|
689
701
|
|
|
690
702
|
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
|
|
691
|
-
insertMany(doc: T | DocumentDefinition<T>, options
|
|
692
|
-
insertMany(
|
|
703
|
+
insertMany(doc: T | DocumentDefinition<T>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
|
|
704
|
+
insertMany(doc: T | DocumentDefinition<T>, options?: InsertManyOptions): Promise<T>;
|
|
705
|
+
insertMany(docs: Array<T | DocumentDefinition<T>>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
|
|
706
|
+
insertMany(docs: Array<T | DocumentDefinition<T>>, options?: InsertManyOptions): Promise<Array<T>>;
|
|
693
707
|
insertMany(doc: T | DocumentDefinition<T>, options?: InsertManyOptions, callback?: (err: CallbackError, res: T | InsertManyResult) => void): void;
|
|
694
708
|
insertMany(docs: Array<T | DocumentDefinition<T>>, options?: InsertManyOptions, callback?: (err: CallbackError, res: Array<T> | InsertManyResult) => void): void;
|
|
695
709
|
|
|
@@ -708,6 +722,8 @@ declare module "mongoose" {
|
|
|
708
722
|
/** Populates document references. */
|
|
709
723
|
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
710
724
|
callback?: (err: any, res: T[]) => void): Promise<Array<T>>;
|
|
725
|
+
populate(doc: any, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
726
|
+
callback?: (err: any, res: T) => void): Promise<T>;
|
|
711
727
|
|
|
712
728
|
/**
|
|
713
729
|
* Makes the indexes in MongoDB match the indexes defined in this model's
|
|
@@ -769,6 +785,7 @@ declare module "mongoose" {
|
|
|
769
785
|
findByIdAndRemove(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
770
786
|
|
|
771
787
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
788
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
772
789
|
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
773
790
|
|
|
774
791
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
@@ -778,9 +795,11 @@ declare module "mongoose" {
|
|
|
778
795
|
findOneAndRemove(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
779
796
|
|
|
780
797
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
798
|
+
findOneAndReplace(filter: FilterQuery<T>, replacement: DocumentDefinition<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
781
799
|
findOneAndReplace(filter?: FilterQuery<T>, replacement?: DocumentDefinition<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
782
800
|
|
|
783
801
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
802
|
+
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
784
803
|
findOneAndUpdate(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
785
804
|
|
|
786
805
|
geoSearch(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: (err: CallbackError, res: Array<T>) => void): Query<Array<T>, T>;
|
|
@@ -800,6 +819,7 @@ declare module "mongoose" {
|
|
|
800
819
|
schema: Schema;
|
|
801
820
|
|
|
802
821
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
822
|
+
findOneAndReplace(filter: FilterQuery<T>, replacement: DocumentDefinition<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
803
823
|
findOneAndReplace(filter?: FilterQuery<T>, replacement?: DocumentDefinition<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
804
824
|
|
|
805
825
|
/** Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option. */
|
|
@@ -874,8 +894,7 @@ declare module "mongoose" {
|
|
|
874
894
|
writeConcern?: any;
|
|
875
895
|
}
|
|
876
896
|
|
|
877
|
-
|
|
878
|
-
type ModelUpdateOptions = QueryOptions;
|
|
897
|
+
type MongooseQueryOptions = Pick<QueryOptions, "populate" | "lean" | "omitUndefined" | "strict" | "useFindAndModify">;
|
|
879
898
|
|
|
880
899
|
interface SaveOptions {
|
|
881
900
|
checkKeys?: boolean;
|
|
@@ -1005,7 +1024,7 @@ declare module "mongoose" {
|
|
|
1005
1024
|
useProjection?: boolean;
|
|
1006
1025
|
}
|
|
1007
1026
|
|
|
1008
|
-
class Schema extends events.EventEmitter {
|
|
1027
|
+
class Schema<T = any> extends events.EventEmitter {
|
|
1009
1028
|
/**
|
|
1010
1029
|
* Create a new schema
|
|
1011
1030
|
*/
|
|
@@ -1014,9 +1033,19 @@ declare module "mongoose" {
|
|
|
1014
1033
|
/** Adds key path / schema type pairs to this schema. */
|
|
1015
1034
|
add(obj: SchemaDefinition | Schema, prefix?: string): this;
|
|
1016
1035
|
|
|
1036
|
+
/**
|
|
1037
|
+
* Array of child schemas (from document arrays and single nested subdocs)
|
|
1038
|
+
* and their corresponding compiled models. Each element of the array is
|
|
1039
|
+
* an object with 2 properties: `schema` and `model`.
|
|
1040
|
+
*/
|
|
1041
|
+
childSchemas: { schema: Schema, model: any }[];
|
|
1042
|
+
|
|
1017
1043
|
/** Returns a copy of this schema */
|
|
1018
1044
|
clone(): Schema;
|
|
1019
1045
|
|
|
1046
|
+
/** Object containing discriminators defined on this schema */
|
|
1047
|
+
discriminators?: { [name: string]: Schema };
|
|
1048
|
+
|
|
1020
1049
|
/** Iterates the schemas paths similar to Array#forEach. */
|
|
1021
1050
|
eachPath(fn: (path: string, type: SchemaType) => void): this;
|
|
1022
1051
|
|
|
@@ -1067,18 +1096,18 @@ declare module "mongoose" {
|
|
|
1067
1096
|
plugin(fn: (schema: Schema, opts?: any) => void, opts?: any): this;
|
|
1068
1097
|
|
|
1069
1098
|
/** Defines a post hook for the model. */
|
|
1070
|
-
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, res: any, next: (err
|
|
1099
|
+
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, res: any, next: (err?: CallbackError) => void) => void): this;
|
|
1071
1100
|
post<T extends Query<any, any> = Query<any, any>>(method: string | RegExp, fn: (this: T, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1072
1101
|
post<T extends Aggregate<any> = Aggregate<any>>(method: "aggregate" | RegExp, fn: (this: T, res: Array<any>, next: (err: CallbackError) => void) => void): this;
|
|
1073
1102
|
post<T extends Model<any> = Model<any>>(method: "insertMany" | RegExp, fn: (this: T, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1074
1103
|
|
|
1075
|
-
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, err: NativeError, res: any, next: (err
|
|
1104
|
+
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, err: NativeError, res: any, next: (err?: CallbackError) => void) => void): this;
|
|
1076
1105
|
post<T extends Query<any, any> = Query<any, any>>(method: string | RegExp, fn: (this: T, err: NativeError, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1077
1106
|
post<T extends Aggregate<any> = Aggregate<any>>(method: "aggregate" | RegExp, fn: (this: T, err: NativeError, res: Array<any>, next: (err: CallbackError) => void) => void): this;
|
|
1078
1107
|
post<T extends Model<any> = Model<any>>(method: "insertMany" | RegExp, fn: (this: T, err: NativeError, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1079
1108
|
|
|
1080
1109
|
/** Defines a pre hook for the model. */
|
|
1081
|
-
pre<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, next: (err
|
|
1110
|
+
pre<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, next: (err?: CallbackError) => void) => void): this;
|
|
1082
1111
|
pre<T extends Query<any, any> = Query<any, any>>(method: string | RegExp, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
1083
1112
|
pre<T extends Aggregate<any> = Aggregate<any>>(method: "aggregate" | RegExp, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
1084
1113
|
pre<T extends Model<any> = Model<any>>(method: "insertMany" | RegExp, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
@@ -1108,6 +1137,9 @@ declare module "mongoose" {
|
|
|
1108
1137
|
/** Creates a virtual type with the given name. */
|
|
1109
1138
|
virtual(name: string, options?: any): VirtualType;
|
|
1110
1139
|
|
|
1140
|
+
/** Object of currently defined virtuals on this schema */
|
|
1141
|
+
virtuals: any;
|
|
1142
|
+
|
|
1111
1143
|
/** Returns the virtual type with the given `name`. */
|
|
1112
1144
|
virtualpath(name: string): VirtualType | null;
|
|
1113
1145
|
}
|
|
@@ -1285,7 +1317,7 @@ declare module "mongoose" {
|
|
|
1285
1317
|
alias?: string;
|
|
1286
1318
|
|
|
1287
1319
|
/** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
|
|
1288
|
-
validate?: RegExp | [RegExp, string] | Function | [Function , string];
|
|
1320
|
+
validate?: RegExp | [RegExp, string] | Function | [Function , string] | ValidateOpts<T> | ValidateOpts<T>[];
|
|
1289
1321
|
|
|
1290
1322
|
/** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
|
|
1291
1323
|
cast?: string;
|
|
@@ -1371,7 +1403,7 @@ declare module "mongoose" {
|
|
|
1371
1403
|
max?: number | Date;
|
|
1372
1404
|
|
|
1373
1405
|
/** Defines a TTL index on this path. Only allowed for dates. */
|
|
1374
|
-
expires?: Date;
|
|
1406
|
+
expires?: number | Date;
|
|
1375
1407
|
|
|
1376
1408
|
/** If `true`, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays. */
|
|
1377
1409
|
excludeIndexes?: boolean;
|
|
@@ -1402,6 +1434,8 @@ declare module "mongoose" {
|
|
|
1402
1434
|
|
|
1403
1435
|
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
|
|
1404
1436
|
maxlength?: number | [number, string];
|
|
1437
|
+
|
|
1438
|
+
[other: string]: any;
|
|
1405
1439
|
}
|
|
1406
1440
|
|
|
1407
1441
|
interface IndexOptions {
|
|
@@ -1412,7 +1446,40 @@ declare module "mongoose" {
|
|
|
1412
1446
|
unique?: boolean
|
|
1413
1447
|
}
|
|
1414
1448
|
|
|
1449
|
+
interface ValidatorProps {
|
|
1450
|
+
path: string;
|
|
1451
|
+
value: any;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
interface ValidatorMessageFn {
|
|
1455
|
+
(props: ValidatorProps): string;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
interface ValidateFn<T> {
|
|
1459
|
+
(value: T): boolean;
|
|
1460
|
+
}
|
|
1461
|
+
|
|
1462
|
+
interface LegacyAsyncValidateFn<T> {
|
|
1463
|
+
(value: T, done: (result: boolean) => void): void;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
interface AsyncValidateFn<T> {
|
|
1467
|
+
(value: any): Promise<boolean>;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
interface ValidateOpts<T> {
|
|
1471
|
+
msg?: string;
|
|
1472
|
+
message?: string | ValidatorMessageFn;
|
|
1473
|
+
type?: string;
|
|
1474
|
+
validator: ValidateFn<T> | LegacyAsyncValidateFn<T> | AsyncValidateFn<T>;
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1415
1477
|
class VirtualType {
|
|
1478
|
+
/** Applies getters to `value`. */
|
|
1479
|
+
applyGetters(value: any, doc: Document): any;
|
|
1480
|
+
/** Applies setters to `value`. */
|
|
1481
|
+
applySetters(value: any, doc: Document): any;
|
|
1482
|
+
|
|
1416
1483
|
/** Adds a custom getter to this virtual. */
|
|
1417
1484
|
get(fn: Function): this;
|
|
1418
1485
|
/** Adds a custom setter to this virtual. */
|
|
@@ -1595,7 +1662,7 @@ declare module "mongoose" {
|
|
|
1595
1662
|
shift(): T;
|
|
1596
1663
|
|
|
1597
1664
|
/** Returns a native js Array. */
|
|
1598
|
-
toObject(options
|
|
1665
|
+
toObject(options?: ToObjectOptions): any;
|
|
1599
1666
|
|
|
1600
1667
|
/** Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking. */
|
|
1601
1668
|
unshift(...args: any[]): number;
|
|
@@ -1637,7 +1704,7 @@ declare module "mongoose" {
|
|
|
1637
1704
|
|
|
1638
1705
|
class Map<V> extends global.Map<string, V> {
|
|
1639
1706
|
/** Converts a Mongoose map into a vanilla JavaScript map. */
|
|
1640
|
-
toObject(options
|
|
1707
|
+
toObject(options?: ToObjectOptions & { flattenMaps?: boolean }): any;
|
|
1641
1708
|
}
|
|
1642
1709
|
|
|
1643
1710
|
var ObjectId: ObjectIdConstructor;
|
|
@@ -1667,6 +1734,8 @@ declare module "mongoose" {
|
|
|
1667
1734
|
}
|
|
1668
1735
|
|
|
1669
1736
|
interface Query<ResultType, DocType extends Document> {
|
|
1737
|
+
_mongooseOptions: MongooseQueryOptions;
|
|
1738
|
+
|
|
1670
1739
|
exec(): Promise<ResultType>;
|
|
1671
1740
|
exec(callback?: (err: CallbackError, res: ResultType) => void): void;
|
|
1672
1741
|
|
|
@@ -1783,12 +1852,14 @@ declare module "mongoose" {
|
|
|
1783
1852
|
findOneAndRemove(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1784
1853
|
|
|
1785
1854
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1855
|
+
findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: DocType, res: any) => void): Query<DocType, DocType>;
|
|
1786
1856
|
findOneAndUpdate(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1787
1857
|
|
|
1788
1858
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
1789
1859
|
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1790
1860
|
|
|
1791
1861
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
1862
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: DocType, res: any) => void): Query<DocType, DocType>;
|
|
1792
1863
|
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1793
1864
|
|
|
1794
1865
|
/** Specifies a `$geometry` condition */
|
|
@@ -1882,7 +1953,7 @@ declare module "mongoose" {
|
|
|
1882
1953
|
* Getter/setter around the current mongoose-specific options for this query
|
|
1883
1954
|
* Below are the current Mongoose-specific options.
|
|
1884
1955
|
*/
|
|
1885
|
-
mongooseOptions(val?:
|
|
1956
|
+
mongooseOptions(val?: MongooseQueryOptions): MongooseQueryOptions;
|
|
1886
1957
|
|
|
1887
1958
|
/** Specifies a `$ne` query condition. When called with one argument, the most recent path passed to `where()` is used. */
|
|
1888
1959
|
ne(val: any): this;
|
|
@@ -1907,7 +1978,7 @@ declare module "mongoose" {
|
|
|
1907
1978
|
* This is handy for integrating with async/await, because `orFail()` saves you
|
|
1908
1979
|
* an extra `if` statement to check if no document was found.
|
|
1909
1980
|
*/
|
|
1910
|
-
orFail(err?: NativeError | (() => NativeError)):
|
|
1981
|
+
orFail(err?: NativeError | (() => NativeError)): Query<NonNullable<ResultType>, DocType>;
|
|
1911
1982
|
|
|
1912
1983
|
/** Specifies a `$polygon` condition */
|
|
1913
1984
|
polygon(...coordinatePairs: number[][]): this;
|
|
@@ -2008,7 +2079,7 @@ declare module "mongoose" {
|
|
|
2008
2079
|
then: Promise<ResultType>["then"];
|
|
2009
2080
|
|
|
2010
2081
|
/** Converts this query to a customized, reusable query constructor with all arguments and options retained. */
|
|
2011
|
-
toConstructor(): new (
|
|
2082
|
+
toConstructor(): new (...args: any[]) => Query<ResultType, DocType>;
|
|
2012
2083
|
|
|
2013
2084
|
/** Declare and/or execute this query as an update() operation. */
|
|
2014
2085
|
update(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: CallbackError, res: any) => void): Query<any, DocType>;
|
|
@@ -2062,7 +2133,10 @@ declare module "mongoose" {
|
|
|
2062
2133
|
|
|
2063
2134
|
export type UpdateQuery<T> = mongodb.UpdateQuery<DocumentDefinition<T>> & mongodb.MatchKeysAndValues<DocumentDefinition<T>>;
|
|
2064
2135
|
|
|
2065
|
-
|
|
2136
|
+
type _AllowStringsForIds<T> = {
|
|
2137
|
+
[K in keyof T]: [Extract<T[K], mongodb.ObjectId>] extends [never] ? T[K] : T[K] | string;
|
|
2138
|
+
};
|
|
2139
|
+
export type DocumentDefinition<T> = _AllowStringsForIds<Omit<Omit<T, Exclude<keyof Document, '_id'>>, FunctionPropertyNames<T>>>;
|
|
2066
2140
|
|
|
2067
2141
|
type FunctionPropertyNames<T> = {
|
|
2068
2142
|
// The 1 & T[K] check comes from: https://stackoverflow.com/questions/55541275/typescript-check-for-the-any-type
|
|
@@ -2086,7 +2160,7 @@ declare module "mongoose" {
|
|
|
2086
2160
|
T[K];
|
|
2087
2161
|
};
|
|
2088
2162
|
|
|
2089
|
-
export type LeanDocument<T> = Omit<Omit<_LeanDocument<T>, Exclude<keyof Document, '_id'>>, FunctionPropertyNames<T>>;
|
|
2163
|
+
export type LeanDocument<T> = Omit<Omit<_LeanDocument<T>, Exclude<keyof Document, '_id' | 'id'>>, FunctionPropertyNames<T>>;
|
|
2090
2164
|
|
|
2091
2165
|
export type LeanDocumentOrArray<T> = 0 extends (1 & T) ? T :
|
|
2092
2166
|
T extends unknown[] ? LeanDocument<T[number]>[] :
|
|
@@ -2173,9 +2247,27 @@ declare module "mongoose" {
|
|
|
2173
2247
|
/** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
|
|
2174
2248
|
hint(value: object | string): this;
|
|
2175
2249
|
|
|
2250
|
+
/**
|
|
2251
|
+
* Appends a new $limit operator to this aggregate pipeline.
|
|
2252
|
+
* @param num maximum number of records to pass to the next stage
|
|
2253
|
+
*/
|
|
2254
|
+
limit(num: number): this;
|
|
2255
|
+
|
|
2176
2256
|
/** Appends new custom $lookup operator to this aggregate pipeline. */
|
|
2177
2257
|
lookup(options: any): this;
|
|
2178
2258
|
|
|
2259
|
+
/**
|
|
2260
|
+
* Appends a new custom $match operator to this aggregate pipeline.
|
|
2261
|
+
* @param arg $match operator contents
|
|
2262
|
+
*/
|
|
2263
|
+
match(arg: any): this;
|
|
2264
|
+
|
|
2265
|
+
/**
|
|
2266
|
+
* Binds this aggregate to a model.
|
|
2267
|
+
* @param model the model to which the aggregate is to be bound
|
|
2268
|
+
*/
|
|
2269
|
+
model(model: any): this;
|
|
2270
|
+
|
|
2179
2271
|
/** Returns the current pipeline */
|
|
2180
2272
|
pipeline(): any[];
|
|
2181
2273
|
|
|
@@ -2202,6 +2294,12 @@ declare module "mongoose" {
|
|
|
2202
2294
|
|
|
2203
2295
|
/** Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html). */
|
|
2204
2296
|
session(session: mongodb.ClientSession | null): this;
|
|
2297
|
+
|
|
2298
|
+
/**
|
|
2299
|
+
* Appends a new $skip operator to this aggregate pipeline.
|
|
2300
|
+
* @param num number of records to skip before next stage
|
|
2301
|
+
*/
|
|
2302
|
+
skip(num: number): this;
|
|
2205
2303
|
|
|
2206
2304
|
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
2207
2305
|
sort(arg: any): this;
|
|
@@ -2423,4 +2521,33 @@ declare module "mongoose" {
|
|
|
2423
2521
|
modifiedPaths: Array<string>;
|
|
2424
2522
|
}
|
|
2425
2523
|
}
|
|
2524
|
+
|
|
2525
|
+
/** Deprecated types for backwards compatibility. */
|
|
2526
|
+
|
|
2527
|
+
/** Alias for QueryOptions for backwards compatability. */
|
|
2528
|
+
type ModelUpdateOptions = QueryOptions;
|
|
2529
|
+
|
|
2530
|
+
/** Backwards support for DefinitelyTyped */
|
|
2531
|
+
interface HookSyncCallback<T> {
|
|
2532
|
+
(this: T, next: HookNextFunction, docs: any[]): Promise<any> | void;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
interface HookAsyncCallback<T> {
|
|
2536
|
+
(this: T, next: HookNextFunction, done: HookDoneFunction, docs: any[]): Promise<any> | void;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
interface HookErrorCallback {
|
|
2540
|
+
(error?: Error): any;
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
interface HookNextFunction {
|
|
2544
|
+
(error?: Error): any;
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
interface HookDoneFunction {
|
|
2548
|
+
(error?: Error): any;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
export type SchemaTypeOpts<T> = SchemaTypeOptions<T>;
|
|
2552
|
+
export type ConnectionOptions = ConnectOptions;
|
|
2426
2553
|
}
|
package/lib/model.js
CHANGED
|
@@ -3332,9 +3332,13 @@ Model.$__insertMany = function(arr, options, callback) {
|
|
|
3332
3332
|
|
|
3333
3333
|
// `insertedDocs` is a Mongoose-specific property
|
|
3334
3334
|
const erroredIndexes = new Set(get(error, 'writeErrors', []).map(err => err.index));
|
|
3335
|
-
error.insertedDocs = docAttributes.
|
|
3336
|
-
|
|
3337
|
-
|
|
3335
|
+
error.insertedDocs = docAttributes.
|
|
3336
|
+
filter((doc, i) => !erroredIndexes.has(i)).
|
|
3337
|
+
map(function setIsNewForInsertedDoc(doc) {
|
|
3338
|
+
doc.$__reset();
|
|
3339
|
+
_setIsNew(doc, false);
|
|
3340
|
+
return doc;
|
|
3341
|
+
});
|
|
3338
3342
|
|
|
3339
3343
|
callback(error, null);
|
|
3340
3344
|
return;
|
package/lib/schema/map.js
CHANGED
|
@@ -31,11 +31,23 @@ class Map extends SchemaType {
|
|
|
31
31
|
|
|
32
32
|
if (val instanceof global.Map) {
|
|
33
33
|
for (const key of val.keys()) {
|
|
34
|
-
|
|
34
|
+
let _val = val.get(key);
|
|
35
|
+
if (_val == null) {
|
|
36
|
+
_val = map.$__schemaType._castNullish(_val);
|
|
37
|
+
} else {
|
|
38
|
+
_val = map.$__schemaType.cast(_val, doc, true);
|
|
39
|
+
}
|
|
40
|
+
map.$init(key, _val);
|
|
35
41
|
}
|
|
36
42
|
} else {
|
|
37
43
|
for (const key of Object.keys(val)) {
|
|
38
|
-
|
|
44
|
+
let _val = val[key];
|
|
45
|
+
if (_val == null) {
|
|
46
|
+
_val = map.$__schemaType._castNullish(_val);
|
|
47
|
+
} else {
|
|
48
|
+
_val = map.$__schemaType.cast(_val, doc, true);
|
|
49
|
+
}
|
|
50
|
+
map.$init(key, _val);
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
53
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "5.11.
|
|
4
|
+
"version": "5.11.8",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/mongodb": "^3.5.27",
|
|
23
23
|
"bson": "^1.1.4",
|
|
24
|
-
"kareem": "2.3.
|
|
24
|
+
"kareem": "2.3.2",
|
|
25
25
|
"mongodb": "3.6.3",
|
|
26
26
|
"mongoose-legacy-pluralize": "1.0.2",
|
|
27
|
-
"mpath": "0.8.
|
|
28
|
-
"mquery": "3.2.
|
|
27
|
+
"mpath": "0.8.1",
|
|
28
|
+
"mquery": "3.2.3",
|
|
29
29
|
"ms": "2.1.2",
|
|
30
30
|
"regexp-clone": "1.0.0",
|
|
31
31
|
"safe-buffer": "5.2.1",
|