mongoose 6.2.10 → 6.3.1
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/.eslintrc.json +157 -157
- package/dist/browser.umd.js +2 -1693
- package/lib/aggregate.js +23 -31
- package/lib/collection.js +0 -7
- package/lib/cursor/ChangeStream.js +42 -2
- package/lib/cursor/QueryCursor.js +2 -0
- package/lib/document.js +13 -19
- package/lib/error/cast.js +7 -2
- package/lib/error/eachAsyncMultiError.js +41 -0
- package/lib/helpers/cursor/eachAsync.js +44 -12
- package/lib/helpers/indexes/applySchemaCollation.js +13 -0
- package/lib/helpers/indexes/isTextIndex.js +16 -0
- package/lib/helpers/model/discriminator.js +1 -3
- package/lib/helpers/populate/getModelsMapForPopulate.js +13 -10
- package/lib/helpers/query/applyGlobalOption.js +29 -0
- package/lib/helpers/query/castUpdate.js +3 -1
- package/lib/helpers/schematype/handleImmutable.js +4 -1
- package/lib/helpers/timestamps/setupTimestamps.js +2 -2
- package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
- package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
- package/lib/index.js +11 -4
- package/lib/model.js +36 -36
- package/lib/query.js +59 -26
- package/lib/queryhelpers.js +11 -1
- package/lib/schema/SubdocumentPath.js +2 -1
- package/lib/schema/documentarray.js +2 -4
- package/lib/schema/objectid.js +0 -3
- package/lib/schema/string.js +24 -2
- package/lib/schema.js +117 -3
- package/lib/schematype.js +2 -3
- package/lib/types/DocumentArray/methods/index.js +1 -1
- package/lib/types/array/methods/index.js +9 -10
- package/lib/types/subdocument.js +29 -0
- package/lib/validoptions.js +1 -0
- package/package.json +13 -7
- package/tools/repl.js +2 -1
- package/tsconfig.json +2 -1
- package/types/aggregate.d.ts +223 -0
- package/types/connection.d.ts +2 -2
- package/types/cursor.d.ts +10 -4
- package/types/document.d.ts +3 -3
- package/types/index.d.ts +200 -215
- package/types/mongooseoptions.d.ts +10 -4
- package/CHANGELOG.md +0 -7227
- package/History.md +0 -1
- package/lib/helpers/query/applyGlobalMaxTimeMS.js +0 -15
package/lib/schema.js
CHANGED
|
@@ -22,6 +22,7 @@ const readPref = require('./driver').get().ReadPreference;
|
|
|
22
22
|
const setupTimestamps = require('./helpers/timestamps/setupTimestamps');
|
|
23
23
|
const utils = require('./utils');
|
|
24
24
|
const validateRef = require('./helpers/populate/validateRef');
|
|
25
|
+
const util = require('util');
|
|
25
26
|
|
|
26
27
|
let MongooseTypes;
|
|
27
28
|
|
|
@@ -53,7 +54,7 @@ let id = 0;
|
|
|
53
54
|
* - [autoCreate](/docs/guide.html#autoCreate): bool - defaults to null (which means use the connection's autoCreate option)
|
|
54
55
|
* - [bufferCommands](/docs/guide.html#bufferCommands): bool - defaults to true
|
|
55
56
|
* - [bufferTimeoutMS](/docs/guide.html#bufferTimeoutMS): number - defaults to 10000 (10 seconds). If `bufferCommands` is enabled, the amount of time Mongoose will wait for connectivity to be restablished before erroring out.
|
|
56
|
-
* - [capped](/docs/guide.html#capped): bool - defaults to false
|
|
57
|
+
* - [capped](/docs/guide.html#capped): bool | number | object - defaults to false
|
|
57
58
|
* - [collection](/docs/guide.html#collection): string - no default
|
|
58
59
|
* - [discriminatorKey](/docs/guide.html#discriminatorKey): string - defaults to `__t`
|
|
59
60
|
* - [id](/docs/guide.html#id): bool - defaults to true
|
|
@@ -370,6 +371,9 @@ Schema.prototype._clone = function _clone(Constructor) {
|
|
|
370
371
|
if (this.discriminators != null) {
|
|
371
372
|
s.discriminators = Object.assign({}, this.discriminators);
|
|
372
373
|
}
|
|
374
|
+
if (this._applyDiscriminators != null) {
|
|
375
|
+
s._applyDiscriminators = Object.assign({}, this._applyDiscriminators);
|
|
376
|
+
}
|
|
373
377
|
|
|
374
378
|
s.aliases = Object.assign({}, this.aliases);
|
|
375
379
|
|
|
@@ -469,6 +473,11 @@ Schema.prototype.defaultOptions = function(options) {
|
|
|
469
473
|
return options;
|
|
470
474
|
};
|
|
471
475
|
|
|
476
|
+
Schema.prototype.discriminator = function(name, schema) {
|
|
477
|
+
this._applyDiscriminators = {};
|
|
478
|
+
this._applyDiscriminators[name] = schema;
|
|
479
|
+
};
|
|
480
|
+
|
|
472
481
|
/**
|
|
473
482
|
* Adds key path / schema type pairs to this schema.
|
|
474
483
|
*
|
|
@@ -510,7 +519,6 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
510
519
|
|
|
511
520
|
const keys = Object.keys(obj);
|
|
512
521
|
const typeKey = this.options.typeKey;
|
|
513
|
-
|
|
514
522
|
for (const key of keys) {
|
|
515
523
|
const fullPath = prefix + key;
|
|
516
524
|
const val = obj[key];
|
|
@@ -540,6 +548,25 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
540
548
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
541
549
|
}
|
|
542
550
|
this.path(prefix + key, val);
|
|
551
|
+
if (val[0] != null && !(val[0].instanceOfSchema) && utils.isPOJO(val[0].discriminators)) {
|
|
552
|
+
const schemaType = this.path(prefix + key);
|
|
553
|
+
for (const key in val[0].discriminators) {
|
|
554
|
+
schemaType.discriminator(key, val[0].discriminators[key]);
|
|
555
|
+
}
|
|
556
|
+
} else if (val[0] != null && val[0].instanceOfSchema && utils.isPOJO(val[0]._applyDiscriminators)) {
|
|
557
|
+
const applyDiscriminators = val[0]._applyDiscriminators || [];
|
|
558
|
+
const schemaType = this.path(prefix + key);
|
|
559
|
+
for (const disc in applyDiscriminators) {
|
|
560
|
+
schemaType.discriminator(disc, applyDiscriminators[disc]);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
else if (val != null && val.instanceOfSchema && utils.isPOJO(val._applyDiscriminators)) {
|
|
564
|
+
const applyDiscriminators = val._applyDiscriminators || [];
|
|
565
|
+
const schemaType = this.path(prefix + key);
|
|
566
|
+
for (const disc in applyDiscriminators) {
|
|
567
|
+
schemaType.discriminator(disc, applyDiscriminators[disc]);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
543
570
|
} else if (Object.keys(val).length < 1) {
|
|
544
571
|
// Special-case: {} always interpreted as Mixed path so leaf at this node
|
|
545
572
|
if (prefix) {
|
|
@@ -569,6 +596,12 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
569
596
|
this.nested[prefix.substring(0, prefix.length - 1)] = true;
|
|
570
597
|
}
|
|
571
598
|
this.path(prefix + key, val);
|
|
599
|
+
if (val != null && !(val.instanceOfSchema) && utils.isPOJO(val.discriminators)) {
|
|
600
|
+
const schemaType = this.path(prefix + key);
|
|
601
|
+
for (const key in val.discriminators) {
|
|
602
|
+
schemaType.discriminator(key, val.discriminators[key]);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
572
605
|
}
|
|
573
606
|
}
|
|
574
607
|
}
|
|
@@ -579,6 +612,86 @@ Schema.prototype.add = function add(obj, prefix) {
|
|
|
579
612
|
return this;
|
|
580
613
|
};
|
|
581
614
|
|
|
615
|
+
/**
|
|
616
|
+
* Remove an index by name or index specification.
|
|
617
|
+
*
|
|
618
|
+
* removeIndex only removes indexes from your schema object. Does **not** affect the indexes
|
|
619
|
+
* in MongoDB.
|
|
620
|
+
*
|
|
621
|
+
* ####Example:
|
|
622
|
+
*
|
|
623
|
+
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
624
|
+
*
|
|
625
|
+
* // Add a new index on { name, color }
|
|
626
|
+
* ToySchema.index({ name: 1, color: 1 });
|
|
627
|
+
*
|
|
628
|
+
* // Remove index on { name, color }
|
|
629
|
+
* // Keep in mind that order matters! `removeIndex({ color: 1, name: 1 })` won't remove the index
|
|
630
|
+
* ToySchema.removeIndex({ name: 1, color: 1 });
|
|
631
|
+
*
|
|
632
|
+
* // Add an index with a custom name
|
|
633
|
+
* ToySchema.index({ color: 1 }, { name: 'my custom index name' });
|
|
634
|
+
* // Remove index by name
|
|
635
|
+
* ToySchema.removeIndex('my custom index name');
|
|
636
|
+
*
|
|
637
|
+
* @param {Object|string} index name or index specification
|
|
638
|
+
* @return {Schema} the Schema instance
|
|
639
|
+
* @api public
|
|
640
|
+
*/
|
|
641
|
+
|
|
642
|
+
Schema.prototype.removeIndex = function removeIndex(index) {
|
|
643
|
+
if (arguments.length > 1) {
|
|
644
|
+
throw new Error('removeIndex() takes only 1 argument');
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
if (typeof index !== 'object' && typeof index !== 'string') {
|
|
648
|
+
throw new Error('removeIndex() may only take either an object or a string as an argument');
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (typeof index === 'object') {
|
|
652
|
+
for (let i = this._indexes.length - 1; i >= 0; --i) {
|
|
653
|
+
if (util.isDeepStrictEqual(this._indexes[i][0], index)) {
|
|
654
|
+
this._indexes.splice(i, 1);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
} else {
|
|
658
|
+
for (let i = this._indexes.length - 1; i >= 0; --i) {
|
|
659
|
+
if (this._indexes[i][1] != null && this._indexes[i][1].name === index) {
|
|
660
|
+
this._indexes.splice(i, 1);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return this;
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* Remove all indexes from this schema.
|
|
670
|
+
*
|
|
671
|
+
* clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
|
|
672
|
+
* in MongoDB.
|
|
673
|
+
*
|
|
674
|
+
* ####Example:
|
|
675
|
+
*
|
|
676
|
+
* const ToySchema = new Schema({ name: String, color: String, price: Number });
|
|
677
|
+
* ToySchema.index({ name: 1 });
|
|
678
|
+
* ToySchema.index({ color: 1 });
|
|
679
|
+
*
|
|
680
|
+
* // Remove all indexes on this schema
|
|
681
|
+
* ToySchema.clearIndexes();
|
|
682
|
+
*
|
|
683
|
+
* ToySchema.indexes(); // []
|
|
684
|
+
*
|
|
685
|
+
* @return {Schema} the Schema instance
|
|
686
|
+
* @api public
|
|
687
|
+
*/
|
|
688
|
+
|
|
689
|
+
Schema.prototype.clearIndexes = function clearIndexes() {
|
|
690
|
+
this._indexes.length = 0;
|
|
691
|
+
|
|
692
|
+
return this;
|
|
693
|
+
};
|
|
694
|
+
|
|
582
695
|
/**
|
|
583
696
|
* Reserved document keys.
|
|
584
697
|
*
|
|
@@ -1010,6 +1123,7 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
|
|
|
1010
1123
|
if (options.hasOwnProperty('strict')) {
|
|
1011
1124
|
childSchemaOptions.strict = options.strict;
|
|
1012
1125
|
}
|
|
1126
|
+
|
|
1013
1127
|
if (this._userProvidedOptions.hasOwnProperty('_id')) {
|
|
1014
1128
|
childSchemaOptions._id = this._userProvidedOptions._id;
|
|
1015
1129
|
} else if (Schema.Types.DocumentArray.defaultOptions._id != null) {
|
|
@@ -1466,7 +1580,7 @@ Schema.prototype.pre = function(name) {
|
|
|
1466
1580
|
* });
|
|
1467
1581
|
*
|
|
1468
1582
|
* schema.post(/Many$/, function(res) {
|
|
1469
|
-
* console.log('this fired after you ran `updateMany()` or `deleteMany()`);
|
|
1583
|
+
* console.log('this fired after you ran `updateMany()` or `deleteMany()`');
|
|
1470
1584
|
* });
|
|
1471
1585
|
*
|
|
1472
1586
|
* const Model = mongoose.model('Model', schema);
|
package/lib/schematype.js
CHANGED
|
@@ -1128,7 +1128,6 @@ SchemaType.prototype.getDefault = function(scope, init) {
|
|
|
1128
1128
|
ret = this.defaultValue;
|
|
1129
1129
|
}
|
|
1130
1130
|
|
|
1131
|
-
|
|
1132
1131
|
if (ret !== null && ret !== undefined) {
|
|
1133
1132
|
if (typeof ret === 'object' && (!this.options || !this.options.shared)) {
|
|
1134
1133
|
ret = utils.clone(ret);
|
|
@@ -1149,7 +1148,7 @@ SchemaType.prototype.getDefault = function(scope, init) {
|
|
|
1149
1148
|
* @api private
|
|
1150
1149
|
*/
|
|
1151
1150
|
|
|
1152
|
-
SchemaType.prototype._applySetters = function(value, scope, init, priorVal) {
|
|
1151
|
+
SchemaType.prototype._applySetters = function(value, scope, init, priorVal, options) {
|
|
1153
1152
|
let v = value;
|
|
1154
1153
|
if (init) {
|
|
1155
1154
|
return v;
|
|
@@ -1157,7 +1156,7 @@ SchemaType.prototype._applySetters = function(value, scope, init, priorVal) {
|
|
|
1157
1156
|
const setters = this.setters;
|
|
1158
1157
|
|
|
1159
1158
|
for (let i = setters.length - 1; i >= 0; i--) {
|
|
1160
|
-
v = setters[i].call(scope, v, priorVal, this);
|
|
1159
|
+
v = setters[i].call(scope, v, priorVal, this, options);
|
|
1161
1160
|
}
|
|
1162
1161
|
|
|
1163
1162
|
return v;
|
|
@@ -149,7 +149,7 @@ const methods = {
|
|
|
149
149
|
*
|
|
150
150
|
* #### NOTE:
|
|
151
151
|
*
|
|
152
|
-
* _Calling this
|
|
152
|
+
* _Calling this multiple times on an array before saving sends the same command as calling it once._
|
|
153
153
|
* _This update is implemented using the MongoDB [$pop](https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._
|
|
154
154
|
*
|
|
155
155
|
* doc.array = [1,2,3];
|
|
@@ -414,9 +414,9 @@ const methods = {
|
|
|
414
414
|
}
|
|
415
415
|
|
|
416
416
|
if (!found) {
|
|
417
|
+
this._markModified();
|
|
417
418
|
rawArray.push(v);
|
|
418
419
|
this._registerAtomic('$addToSet', v);
|
|
419
|
-
this._markModified();
|
|
420
420
|
[].push.call(added, v);
|
|
421
421
|
}
|
|
422
422
|
}, this);
|
|
@@ -510,9 +510,9 @@ const methods = {
|
|
|
510
510
|
|
|
511
511
|
nonAtomicPush() {
|
|
512
512
|
const values = [].map.call(arguments, this._mapCast, this);
|
|
513
|
+
this._markModified();
|
|
513
514
|
const ret = [].push.apply(this, values);
|
|
514
515
|
this._registerAtomic('$set', this);
|
|
515
|
-
this._markModified();
|
|
516
516
|
return ret;
|
|
517
517
|
},
|
|
518
518
|
|
|
@@ -530,9 +530,9 @@ const methods = {
|
|
|
530
530
|
*/
|
|
531
531
|
|
|
532
532
|
pop() {
|
|
533
|
+
this._markModified();
|
|
533
534
|
const ret = [].pop.call(this);
|
|
534
535
|
this._registerAtomic('$set', this);
|
|
535
|
-
this._markModified();
|
|
536
536
|
return ret;
|
|
537
537
|
},
|
|
538
538
|
|
|
@@ -572,6 +572,7 @@ const methods = {
|
|
|
572
572
|
const cur = this[arrayParentSymbol].get(this[arrayPathSymbol]);
|
|
573
573
|
let i = cur.length;
|
|
574
574
|
let mem;
|
|
575
|
+
this._markModified();
|
|
575
576
|
|
|
576
577
|
while (i--) {
|
|
577
578
|
mem = cur[i];
|
|
@@ -595,7 +596,6 @@ const methods = {
|
|
|
595
596
|
this._registerAtomic('$pullAll', values);
|
|
596
597
|
}
|
|
597
598
|
|
|
598
|
-
this._markModified();
|
|
599
599
|
|
|
600
600
|
// Might have modified child paths and then pulled, like
|
|
601
601
|
// `doc.children[1].name = 'test';` followed by
|
|
@@ -657,7 +657,7 @@ const methods = {
|
|
|
657
657
|
undefined, { skipDocumentArrayCast: true });
|
|
658
658
|
let ret;
|
|
659
659
|
const atomics = this[arrayAtomicsSymbol];
|
|
660
|
-
|
|
660
|
+
this._markModified();
|
|
661
661
|
if (isOverwrite) {
|
|
662
662
|
atomic.$each = values;
|
|
663
663
|
|
|
@@ -684,7 +684,6 @@ const methods = {
|
|
|
684
684
|
}
|
|
685
685
|
|
|
686
686
|
this._registerAtomic('$push', atomic);
|
|
687
|
-
this._markModified();
|
|
688
687
|
return ret;
|
|
689
688
|
},
|
|
690
689
|
|
|
@@ -737,8 +736,8 @@ const methods = {
|
|
|
737
736
|
return this;
|
|
738
737
|
}
|
|
739
738
|
const value = methods._cast.call(this, val, i);
|
|
740
|
-
arr[i] = value;
|
|
741
739
|
methods._markModified.call(this, i);
|
|
740
|
+
arr[i] = value;
|
|
742
741
|
return this;
|
|
743
742
|
},
|
|
744
743
|
|
|
@@ -763,9 +762,9 @@ const methods = {
|
|
|
763
762
|
|
|
764
763
|
shift() {
|
|
765
764
|
const arr = utils.isMongooseArray(this) ? this.__array : this;
|
|
765
|
+
this._markModified();
|
|
766
766
|
const ret = [].shift.call(arr);
|
|
767
767
|
this._registerAtomic('$set', this);
|
|
768
|
-
this._markModified();
|
|
769
768
|
return ret;
|
|
770
769
|
},
|
|
771
770
|
|
|
@@ -890,9 +889,9 @@ const methods = {
|
|
|
890
889
|
}
|
|
891
890
|
|
|
892
891
|
const arr = utils.isMongooseArray(this) ? this.__array : this;
|
|
892
|
+
this._markModified();
|
|
893
893
|
[].unshift.apply(arr, values);
|
|
894
894
|
this._registerAtomic('$set', this);
|
|
895
|
-
this._markModified();
|
|
896
895
|
return this.length;
|
|
897
896
|
}
|
|
898
897
|
};
|
package/lib/types/subdocument.js
CHANGED
|
@@ -269,6 +269,35 @@ Subdocument.prototype.ownerDocument = function() {
|
|
|
269
269
|
return this.$__.ownerDocument;
|
|
270
270
|
};
|
|
271
271
|
|
|
272
|
+
/*!
|
|
273
|
+
* ignore
|
|
274
|
+
*/
|
|
275
|
+
|
|
276
|
+
Subdocument.prototype.$__fullPathWithIndexes = function() {
|
|
277
|
+
let parent = this; // eslint-disable-line consistent-this
|
|
278
|
+
const paths = [];
|
|
279
|
+
const seenDocs = new Set([parent]);
|
|
280
|
+
|
|
281
|
+
while (true) {
|
|
282
|
+
if (typeof parent.$__pathRelativeToParent !== 'function') {
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
paths.unshift(parent.$__pathRelativeToParent(void 0, false));
|
|
286
|
+
const _parent = parent.$parent();
|
|
287
|
+
if (_parent == null) {
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
parent = _parent;
|
|
291
|
+
if (seenDocs.has(parent)) {
|
|
292
|
+
throw new Error('Infinite subdocument loop: subdoc with _id ' + parent._id + ' is a parent of itself');
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
seenDocs.add(parent);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return paths.join('.');
|
|
299
|
+
};
|
|
300
|
+
|
|
272
301
|
/**
|
|
273
302
|
* Returns this sub-documents parent document.
|
|
274
303
|
*
|
package/lib/validoptions.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.3.1",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
],
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"bson": "^4.
|
|
22
|
+
"bson": "^4.6.2",
|
|
23
23
|
"kareem": "2.3.5",
|
|
24
|
-
"mongodb": "4.
|
|
24
|
+
"mongodb": "4.5.0",
|
|
25
25
|
"mpath": "0.8.4",
|
|
26
26
|
"mquery": "4.0.2",
|
|
27
27
|
"ms": "2.1.3",
|
|
@@ -35,11 +35,13 @@
|
|
|
35
35
|
"acquit": "1.2.1",
|
|
36
36
|
"acquit-ignore": "0.2.0",
|
|
37
37
|
"acquit-require": "0.1.1",
|
|
38
|
+
"assert-browserify": "npm:assert@^2.0.0",
|
|
38
39
|
"axios": "0.26.1",
|
|
39
40
|
"babel-loader": "8.2.4",
|
|
40
41
|
"benchmark": "2.1.4",
|
|
41
42
|
"bluebird": "3.7.2",
|
|
42
43
|
"cheerio": "1.0.0-rc.10",
|
|
44
|
+
"crypto-browserify": "3.12.0",
|
|
43
45
|
"dox": "0.3.1",
|
|
44
46
|
"eslint": "8.12.0",
|
|
45
47
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
@@ -49,21 +51,25 @@
|
|
|
49
51
|
"marked": "4.0.12",
|
|
50
52
|
"mocha": "9.2.2",
|
|
51
53
|
"moment": "2.x",
|
|
52
|
-
"mongodb-memory-server": "
|
|
53
|
-
"nyc": "
|
|
54
|
+
"mongodb-memory-server": "8.3.0",
|
|
55
|
+
"nyc": "15.1.0",
|
|
54
56
|
"pug": "3.0.2",
|
|
55
57
|
"q": "1.5.1",
|
|
56
58
|
"serve-handler": "6.1.3",
|
|
57
|
-
"
|
|
59
|
+
"sinon": "13.0.0",
|
|
60
|
+
"stream-browserify": "3.0.0",
|
|
61
|
+
"tsd": "0.19.1",
|
|
58
62
|
"typescript": "4.6.3",
|
|
59
63
|
"uuid": "8.3.2",
|
|
60
|
-
"webpack": "
|
|
64
|
+
"webpack": "5.70.0"
|
|
61
65
|
},
|
|
62
66
|
"directories": {
|
|
63
67
|
"lib": "./lib/mongoose"
|
|
64
68
|
},
|
|
65
69
|
"scripts": {
|
|
66
70
|
"lint": "eslint .",
|
|
71
|
+
"lint-js": "eslint . --ext .js",
|
|
72
|
+
"lint-ts": "eslint . --ext .ts",
|
|
67
73
|
"build-browser": "node build-browser.js",
|
|
68
74
|
"prepublishOnly": "npm run build-browser",
|
|
69
75
|
"release": "git pull && git push origin master --tags && npm publish",
|
package/tools/repl.js
CHANGED
|
@@ -17,7 +17,8 @@ async function run() {
|
|
|
17
17
|
// Set the expiry job in MongoDB to run every second
|
|
18
18
|
{
|
|
19
19
|
port: 27017,
|
|
20
|
-
args: ['--setParameter', 'ttlMonitorSleepSecs=1']
|
|
20
|
+
args: ['--setParameter', 'ttlMonitorSleepSecs=1']
|
|
21
|
+
}
|
|
21
22
|
],
|
|
22
23
|
dbName: 'mongoose_test',
|
|
23
24
|
replSet: {
|
package/tsconfig.json
CHANGED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import mongodb = require('mongodb');
|
|
2
|
+
|
|
3
|
+
declare module 'mongoose' {
|
|
4
|
+
|
|
5
|
+
interface AggregateOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If true, the MongoDB server will use the hard drive to store data during this aggregation.
|
|
8
|
+
*/
|
|
9
|
+
allowDiskUse?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Applicable only if you specify the $out or $merge aggregation stages.
|
|
12
|
+
*
|
|
13
|
+
* Enables db.collection.aggregate() to bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements.
|
|
14
|
+
*/
|
|
15
|
+
bypassDocumentValidation?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The BSON-serializer will check if keys are valid
|
|
18
|
+
*/
|
|
19
|
+
collation?: mongodb.CollationOptions;
|
|
20
|
+
/**
|
|
21
|
+
* Users can specify an arbitrary string to help trace the operation through the database profiler, currentOp, and logs.
|
|
22
|
+
*/
|
|
23
|
+
comment?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Specifies the initial batch size for the cursor. The value of the cursor field is a document with the field batchSize.
|
|
26
|
+
*/
|
|
27
|
+
cursor?: { batchSize?: number; };
|
|
28
|
+
/**
|
|
29
|
+
* Specifies to return the information on the processing of the pipeline. See Return Information on Aggregation Pipeline Operation for an example.
|
|
30
|
+
*
|
|
31
|
+
* Not available in multi-document transactions.
|
|
32
|
+
*/
|
|
33
|
+
explain?: mongodb.ExplainVerbosityLike;
|
|
34
|
+
/**
|
|
35
|
+
* The index to use for the aggregation. The index is on the initial collection/view against which the aggregation is run.
|
|
36
|
+
*/
|
|
37
|
+
hint?: string | AnyObject;
|
|
38
|
+
/**
|
|
39
|
+
* Specifies a document with a list of variables. This allows you to improve command readability by separating the variables from the query text.
|
|
40
|
+
*/
|
|
41
|
+
let?: AnyObject;
|
|
42
|
+
/**
|
|
43
|
+
* Specifies a time limit in milliseconds for processing operations on a cursor. If you do not specify a value for maxTimeMS, operations will not time out. A value of 0 explicitly specifies the default unbounded behavior.
|
|
44
|
+
*
|
|
45
|
+
* @see https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/
|
|
46
|
+
*/
|
|
47
|
+
maxTimeMS?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Return BSON filled buffers from operations.
|
|
50
|
+
*/
|
|
51
|
+
raw?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Specifies the read concern.
|
|
54
|
+
*/
|
|
55
|
+
readConcern?: mongodb.ReadConcernLike;
|
|
56
|
+
/**
|
|
57
|
+
* The preferred read preference.
|
|
58
|
+
*/
|
|
59
|
+
readPreference?: mongodb.ReadPreferenceLike;
|
|
60
|
+
/** The ClientSession for this aggregation */
|
|
61
|
+
session?: mongodb.ClientSession;
|
|
62
|
+
/**
|
|
63
|
+
* Specifies the write concern.
|
|
64
|
+
*/
|
|
65
|
+
writeConcern?: mongodb.WriteConcern;
|
|
66
|
+
[key: string]: any;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
class Aggregate<R> {
|
|
70
|
+
/**
|
|
71
|
+
* Returns an asyncIterator for use with [`for/await/of` loops](https://thecodebarbarian.com/getting-started-with-async-iterators-in-node-js
|
|
72
|
+
* You do not need to call this function explicitly, the JavaScript runtime
|
|
73
|
+
* will call it for you.
|
|
74
|
+
*/
|
|
75
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<Unpacked<R>>;
|
|
76
|
+
|
|
77
|
+
options: AggregateOptions;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sets an option on this aggregation. This function will be deprecated in a
|
|
81
|
+
* future release.
|
|
82
|
+
*
|
|
83
|
+
* @deprecated
|
|
84
|
+
*/
|
|
85
|
+
addCursorFlag(flag: CursorFlag, value: boolean): this;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Appends a new $addFields operator to this aggregate pipeline.
|
|
89
|
+
* Requires MongoDB v3.4+ to work
|
|
90
|
+
*/
|
|
91
|
+
addFields(arg: PipelineStage.AddFields['$addFields']): this;
|
|
92
|
+
|
|
93
|
+
/** Sets the allowDiskUse option for the aggregation query (ignored for < 2.6.0) */
|
|
94
|
+
allowDiskUse(value: boolean): this;
|
|
95
|
+
|
|
96
|
+
/** Appends new operators to this aggregate pipeline */
|
|
97
|
+
append(...args: PipelineStage[]): this;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Executes the query returning a `Promise` which will be
|
|
101
|
+
* resolved with either the doc(s) or rejected with the error.
|
|
102
|
+
* Like [`.then()`](#query_Query-then), but only takes a rejection handler.
|
|
103
|
+
*/
|
|
104
|
+
catch: Promise<R>['catch'];
|
|
105
|
+
|
|
106
|
+
/** Set the collation. */
|
|
107
|
+
collation(options: mongodb.CollationOptions): this;
|
|
108
|
+
|
|
109
|
+
/** Appends a new $count operator to this aggregate pipeline. */
|
|
110
|
+
count(fieldName: PipelineStage.Count['$count']): this;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Sets the cursor option for the aggregation query (ignored for < 2.6.0).
|
|
114
|
+
*/
|
|
115
|
+
cursor<DocType = any>(options?: Record<string, unknown>): Cursor<DocType>;
|
|
116
|
+
|
|
117
|
+
/** Executes the aggregate pipeline on the currently bound Model. */
|
|
118
|
+
exec(callback: Callback<R>): void;
|
|
119
|
+
exec(): Promise<R>;
|
|
120
|
+
|
|
121
|
+
/** Execute the aggregation with explain */
|
|
122
|
+
explain(verbosity: mongodb.ExplainVerbosityLike, callback: Callback<AnyObject>): void;
|
|
123
|
+
explain(verbosity: mongodb.ExplainVerbosityLike): Promise<AnyObject>;
|
|
124
|
+
explain(callback: Callback<AnyObject>): void;
|
|
125
|
+
explain(): Promise<AnyObject>;
|
|
126
|
+
|
|
127
|
+
/** Combines multiple aggregation pipelines. */
|
|
128
|
+
facet(options: PipelineStage.Facet['$facet']): this;
|
|
129
|
+
|
|
130
|
+
/** Appends new custom $graphLookup operator(s) to this aggregate pipeline, performing a recursive search on a collection. */
|
|
131
|
+
graphLookup(options: PipelineStage.GraphLookup['$graphLookup']): this;
|
|
132
|
+
|
|
133
|
+
/** Appends new custom $group operator to this aggregate pipeline. */
|
|
134
|
+
group(arg: PipelineStage.Group['$group']): this;
|
|
135
|
+
|
|
136
|
+
/** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
|
|
137
|
+
hint(value: Record<string, unknown> | string): this;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Appends a new $limit operator to this aggregate pipeline.
|
|
141
|
+
* @param num maximum number of records to pass to the next stage
|
|
142
|
+
*/
|
|
143
|
+
limit(num: PipelineStage.Limit['$limit']): this;
|
|
144
|
+
|
|
145
|
+
/** Appends new custom $lookup operator to this aggregate pipeline. */
|
|
146
|
+
lookup(options: PipelineStage.Lookup['$lookup']): this;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Appends a new custom $match operator to this aggregate pipeline.
|
|
150
|
+
* @param arg $match operator contents
|
|
151
|
+
*/
|
|
152
|
+
match(arg: PipelineStage.Match['$match']): this;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Binds this aggregate to a model.
|
|
156
|
+
* @param model the model to which the aggregate is to be bound
|
|
157
|
+
*/
|
|
158
|
+
model(model: Model<any>): this;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Append a new $near operator to this aggregation pipeline
|
|
162
|
+
* @param arg $near operator contents
|
|
163
|
+
*/
|
|
164
|
+
near(arg: { near?: number[]; distanceField: string; maxDistance?: number; query?: Record<string, any>; includeLocs?: string; num?: number; uniqueDocs?: boolean }): this;
|
|
165
|
+
|
|
166
|
+
/** Returns the current pipeline */
|
|
167
|
+
pipeline(): PipelineStage[];
|
|
168
|
+
|
|
169
|
+
/** Appends a new $project operator to this aggregate pipeline. */
|
|
170
|
+
project(arg: PipelineStage.Project['$project']): this;
|
|
171
|
+
|
|
172
|
+
/** Sets the readPreference option for the aggregation query. */
|
|
173
|
+
read(pref: mongodb.ReadPreferenceLike): this;
|
|
174
|
+
|
|
175
|
+
/** Sets the readConcern level for the aggregation query. */
|
|
176
|
+
readConcern(level: string): this;
|
|
177
|
+
|
|
178
|
+
/** Appends a new $redact operator to this aggregate pipeline. */
|
|
179
|
+
redact(expression: PipelineStage.Redact['$redact'], thenExpr: '$$DESCEND' | '$$PRUNE' | '$$KEEP' | AnyObject, elseExpr: '$$DESCEND' | '$$PRUNE' | '$$KEEP' | AnyObject): this;
|
|
180
|
+
|
|
181
|
+
/** Appends a new $replaceRoot operator to this aggregate pipeline. */
|
|
182
|
+
replaceRoot(newRoot: PipelineStage.ReplaceRoot['$replaceRoot']['newRoot'] | string): this;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Helper for [Atlas Text Search](https://docs.atlas.mongodb.com/reference/atlas-search/tutorial/)'s
|
|
186
|
+
* `$search` stage.
|
|
187
|
+
*/
|
|
188
|
+
search(options: PipelineStage.Search['$search']): this;
|
|
189
|
+
|
|
190
|
+
/** Lets you set arbitrary options, for middlewares or plugins. */
|
|
191
|
+
option(value: AggregateOptions): this;
|
|
192
|
+
|
|
193
|
+
/** Appends new custom $sample operator to this aggregate pipeline. */
|
|
194
|
+
sample(arg: PipelineStage.Sample['$sample']['size']): this;
|
|
195
|
+
|
|
196
|
+
/** Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html). */
|
|
197
|
+
session(session: mongodb.ClientSession | null): this;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Appends a new $skip operator to this aggregate pipeline.
|
|
201
|
+
* @param num number of records to skip before next stage
|
|
202
|
+
*/
|
|
203
|
+
skip(num: PipelineStage.Skip['$skip']): this;
|
|
204
|
+
|
|
205
|
+
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
206
|
+
sort(arg: string | Record<string, SortValues> | PipelineStage.Sort['$sort']): this;
|
|
207
|
+
|
|
208
|
+
/** Provides promise for aggregate. */
|
|
209
|
+
then: Promise<R>['then'];
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Appends a new $sortByCount operator to this aggregate pipeline. Accepts either a string field name
|
|
213
|
+
* or a pipeline object.
|
|
214
|
+
*/
|
|
215
|
+
sortByCount(arg: string | PipelineStage.SortByCount['$sortByCount']): this;
|
|
216
|
+
|
|
217
|
+
/** Appends new $unionWith operator to this aggregate pipeline. */
|
|
218
|
+
unionWith(options: PipelineStage.UnionWith['$unionWith']): this;
|
|
219
|
+
|
|
220
|
+
/** Appends new custom $unwind operator(s) to this aggregate pipeline. */
|
|
221
|
+
unwind(...args: PipelineStage.Unwind['$unwind'][]): this;
|
|
222
|
+
}
|
|
223
|
+
}
|