mongoose 6.2.8 → 6.2.11

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.
Files changed (61) hide show
  1. package/.eslintrc.json +35 -26
  2. package/CHANGELOG.md +28 -0
  3. package/dist/browser.umd.js +38 -27
  4. package/lib/aggregate.js +57 -66
  5. package/lib/browser.js +4 -4
  6. package/lib/connection.js +21 -21
  7. package/lib/cursor/AggregationCursor.js +2 -2
  8. package/lib/cursor/QueryCursor.js +3 -3
  9. package/lib/document.js +65 -49
  10. package/lib/error/index.js +2 -2
  11. package/lib/helpers/indexes/applySchemaCollation.js +13 -0
  12. package/lib/helpers/indexes/isTextIndex.js +16 -0
  13. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  14. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  15. package/lib/helpers/query/castUpdate.js +3 -1
  16. package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
  17. package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
  18. package/lib/index.js +24 -26
  19. package/lib/model.js +144 -146
  20. package/lib/options/SchemaArrayOptions.js +2 -2
  21. package/lib/options/SchemaBufferOptions.js +1 -1
  22. package/lib/options/SchemaDateOptions.js +9 -2
  23. package/lib/options/SchemaDocumentArrayOptions.js +3 -3
  24. package/lib/options/SchemaMapOptions.js +2 -2
  25. package/lib/options/SchemaNumberOptions.js +3 -3
  26. package/lib/options/SchemaObjectIdOptions.js +2 -2
  27. package/lib/options/SchemaStringOptions.js +1 -1
  28. package/lib/options/SchemaSubdocumentOptions.js +2 -2
  29. package/lib/options/SchemaTypeOptions.js +3 -3
  30. package/lib/query.js +291 -248
  31. package/lib/schema/SubdocumentPath.js +4 -3
  32. package/lib/schema/array.js +2 -2
  33. package/lib/schema/boolean.js +4 -4
  34. package/lib/schema/buffer.js +3 -3
  35. package/lib/schema/date.js +7 -7
  36. package/lib/schema/decimal128.js +2 -2
  37. package/lib/schema/documentarray.js +3 -3
  38. package/lib/schema/mixed.js +2 -2
  39. package/lib/schema/number.js +6 -6
  40. package/lib/schema/objectid.js +4 -7
  41. package/lib/schema/string.js +38 -16
  42. package/lib/schema.js +30 -29
  43. package/lib/schematype.js +78 -69
  44. package/lib/types/ArraySubdocument.js +1 -1
  45. package/lib/types/DocumentArray/methods/index.js +2 -2
  46. package/lib/types/array/index.js +1 -1
  47. package/lib/types/array/methods/index.js +13 -13
  48. package/lib/types/buffer.js +1 -1
  49. package/lib/types/decimal128.js +1 -1
  50. package/lib/types/objectid.js +1 -1
  51. package/lib/types/subdocument.js +31 -2
  52. package/lib/virtualtype.js +3 -3
  53. package/package.json +18 -16
  54. package/tools/repl.js +8 -8
  55. package/tools/sharded.js +3 -3
  56. package/types/aggregate.d.ts +223 -0
  57. package/types/connection.d.ts +116 -116
  58. package/types/error.d.ts +2 -2
  59. package/types/index.d.ts +76 -213
  60. package/types/pipelinestage.d.ts +194 -194
  61. package/types/schemaoptions.d.ts +2 -2
@@ -100,7 +100,7 @@ const methods = {
100
100
  /**
101
101
  * Atomically shifts the array at most one time per document `save()`.
102
102
  *
103
- * ####NOTE:
103
+ * #### Note:
104
104
  *
105
105
  * _Calling this multiple times on an array before saving sends the same command as calling it once._
106
106
  * _This update is implemented using the MongoDB [$pop](https://www.mongodb.org/display/DOCS/Updating/#Updating-%24pop) method which enforces this restriction._
@@ -149,7 +149,7 @@ const methods = {
149
149
  *
150
150
  * #### NOTE:
151
151
  *
152
- * _Calling this mulitple times on an array before saving sends the same command as calling it once._
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];
@@ -365,7 +365,7 @@ const methods = {
365
365
  /**
366
366
  * Adds values to the array if not already present.
367
367
  *
368
- * ####Example:
368
+ * #### Example:
369
369
  *
370
370
  * console.log(doc.array) // [2,3,4]
371
371
  * const added = doc.array.addToSet(4,5);
@@ -498,7 +498,7 @@ const methods = {
498
498
  /**
499
499
  * Pushes items to the array non-atomically.
500
500
  *
501
- * ####NOTE:
501
+ * #### Note:
502
502
  *
503
503
  * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
504
504
  *
@@ -519,7 +519,7 @@ const methods = {
519
519
  /**
520
520
  * Wraps [`Array#pop`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/pop) with proper change tracking.
521
521
  *
522
- * ####Note:
522
+ * #### Note:
523
523
  *
524
524
  * _marks the entire array as modified which will pass the entire thing to $set potentially overwriting any changes that happen between when you retrieved the object and when you save it._
525
525
  *
@@ -541,7 +541,7 @@ const methods = {
541
541
  * the provided value to an embedded document and comparing using
542
542
  * [the `Document.equals()` function.](/docs/api.html#document_Document-equals)
543
543
  *
544
- * ####Examples:
544
+ * #### Examples:
545
545
  *
546
546
  * doc.array.pull(ObjectId)
547
547
  * doc.array.pull({ _id: 'someId' })
@@ -611,7 +611,7 @@ const methods = {
611
611
  /**
612
612
  * Wraps [`Array#push`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/push) with proper change tracking.
613
613
  *
614
- * ####Example:
614
+ * #### Example:
615
615
  *
616
616
  * const schema = Schema({ nums: [Number] });
617
617
  * const Model = mongoose.model('Test', schema);
@@ -706,7 +706,7 @@ const methods = {
706
706
  /**
707
707
  * Sets the casted `val` at index `i` and marks the array modified.
708
708
  *
709
- * ####Example:
709
+ * #### Example:
710
710
  *
711
711
  * // given documents based on the following
712
712
  * const Doc = mongoose.model('Doc', new Schema({ array: [Number] }));
@@ -745,14 +745,14 @@ const methods = {
745
745
  /**
746
746
  * Wraps [`Array#shift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
747
747
  *
748
- * ####Example:
748
+ * #### Example:
749
749
  *
750
750
  * doc.array = [2,3];
751
751
  * const res = doc.array.shift();
752
752
  * console.log(res) // 2
753
753
  * console.log(doc.array) // [3]
754
754
  *
755
- * ####Note:
755
+ * #### Note:
756
756
  *
757
757
  * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
758
758
  *
@@ -772,7 +772,7 @@ const methods = {
772
772
  /**
773
773
  * Wraps [`Array#sort`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/sort) with proper change tracking.
774
774
  *
775
- * ####NOTE:
775
+ * #### Note:
776
776
  *
777
777
  * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
778
778
  *
@@ -792,7 +792,7 @@ const methods = {
792
792
  /**
793
793
  * Wraps [`Array#splice`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/splice) with proper change tracking and casting.
794
794
  *
795
- * ####Note:
795
+ * #### Note:
796
796
  *
797
797
  * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwritting any changes that happen between when you retrieved the object and when you save it._
798
798
  *
@@ -869,7 +869,7 @@ const methods = {
869
869
  /**
870
870
  * Wraps [`Array#unshift`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/unshift) with proper change tracking.
871
871
  *
872
- * ####Note:
872
+ * #### Note:
873
873
  *
874
874
  * _marks the entire array as modified, which if saved, will store it as a `$set` operation, potentially overwriting any changes that happen between when you retrieved the object and when you save it._
875
875
  *
@@ -113,7 +113,7 @@ MongooseBuffer.mixin = {
113
113
  /**
114
114
  * Copies the buffer.
115
115
  *
116
- * ####Note:
116
+ * #### Note:
117
117
  *
118
118
  * `Buffer#copy` does not mark `target` as modified so you must copy from a `MongooseBuffer` for it to work as expected. This is a work around since `copy` modifies the target, not this.
119
119
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ObjectId type constructor
3
3
  *
4
- * ####Example
4
+ * #### Example
5
5
  *
6
6
  * const id = new mongoose.Types.ObjectId;
7
7
  *
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ObjectId type constructor
3
3
  *
4
- * ####Example
4
+ * #### Example
5
5
  *
6
6
  * const id = new mongoose.Types.ObjectId;
7
7
  *
@@ -58,7 +58,7 @@ Subdocument.prototype.toBSON = function() {
58
58
  /**
59
59
  * Used as a stub for middleware
60
60
  *
61
- * ####NOTE:
61
+ * #### Note:
62
62
  *
63
63
  * _This is a no-op. Does not actually save the doc to the db._
64
64
  *
@@ -116,7 +116,7 @@ Subdocument.prototype.$__pathRelativeToParent = function(p) {
116
116
  /**
117
117
  * Used as a stub for middleware
118
118
  *
119
- * ####NOTE:
119
+ * #### Note:
120
120
  *
121
121
  * _This is a no-op. Does not actually save the doc to the db._
122
122
  *
@@ -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
  *
@@ -7,7 +7,7 @@ const utils = require('./utils');
7
7
  *
8
8
  * This is what mongoose uses to define virtual attributes via `Schema.prototype.virtual`.
9
9
  *
10
- * ####Example:
10
+ * #### Example:
11
11
  *
12
12
  * const fullname = schema.virtual('fullname');
13
13
  * fullname instanceof mongoose.VirtualType // true
@@ -78,7 +78,7 @@ VirtualType.prototype.clone = function() {
78
78
  * - `virtual`: the virtual object you called `.get()` on
79
79
  * - `doc`: the document this virtual is attached to. Equivalent to `this`.
80
80
  *
81
- * ####Example:
81
+ * #### Example:
82
82
  *
83
83
  * const virtual = schema.virtual('fullname');
84
84
  * virtual.get(function(value, virtual, doc) {
@@ -104,7 +104,7 @@ VirtualType.prototype.get = function(fn) {
104
104
  * - `virtual`: the virtual object you're calling `.set()` on
105
105
  * - `doc`: the document this virtual is attached to. Equivalent to `this`.
106
106
  *
107
- * ####Example:
107
+ * #### Example:
108
108
  *
109
109
  * const virtual = schema.virtual('fullname');
110
110
  * virtual.set(function(value, virtual, doc) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.2.8",
4
+ "version": "6.2.11",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -20,7 +20,7 @@
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
22
  "bson": "^4.2.2",
23
- "kareem": "2.3.4",
23
+ "kareem": "2.3.5",
24
24
  "mongodb": "4.3.1",
25
25
  "mpath": "0.8.4",
26
26
  "mquery": "4.0.2",
@@ -28,34 +28,34 @@
28
28
  "sift": "16.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@babel/core": "7.17.5",
31
+ "@babel/core": "7.17.8",
32
32
  "@babel/preset-env": "7.16.11",
33
- "@typescript-eslint/eslint-plugin": "5.12.0",
34
- "@typescript-eslint/parser": "5.12.0",
35
- "acquit": "1.x",
36
- "acquit-ignore": "0.2.x",
37
- "acquit-require": "0.1.x",
33
+ "@typescript-eslint/eslint-plugin": "5.17.0",
34
+ "@typescript-eslint/parser": "5.17.0",
35
+ "acquit": "1.2.1",
36
+ "acquit-ignore": "0.2.0",
37
+ "acquit-require": "0.1.1",
38
38
  "axios": "0.26.1",
39
- "babel-loader": "8.2.3",
39
+ "babel-loader": "8.2.4",
40
40
  "benchmark": "2.1.4",
41
41
  "bluebird": "3.7.2",
42
42
  "cheerio": "1.0.0-rc.10",
43
43
  "dox": "0.3.1",
44
- "eslint": "8.9.0",
44
+ "eslint": "8.12.0",
45
45
  "eslint-plugin-mocha-no-only": "1.1.1",
46
- "highlight.js": "9.18.3",
46
+ "highlight.js": "11.5.0",
47
47
  "lodash.isequal": "4.5.0",
48
48
  "lodash.isequalwith": "4.4.0",
49
- "marked": "2.1.3",
50
- "mocha": "9.2.1",
49
+ "marked": "4.0.12",
50
+ "mocha": "9.2.2",
51
51
  "moment": "2.x",
52
52
  "mongodb-memory-server": "^8.3.0",
53
53
  "nyc": "^15.1.0",
54
54
  "pug": "3.0.2",
55
55
  "q": "1.5.1",
56
56
  "serve-handler": "6.1.3",
57
- "tsd": "0.19.1",
58
- "typescript": "4.5.5",
57
+ "tsd": "0.20.0",
58
+ "typescript": "4.6.3",
59
59
  "uuid": "8.3.2",
60
60
  "webpack": "4.44.1"
61
61
  },
@@ -64,13 +64,15 @@
64
64
  },
65
65
  "scripts": {
66
66
  "lint": "eslint .",
67
+ "lint-js": "eslint . --ext .js",
68
+ "lint-ts": "eslint . --ext .ts",
67
69
  "build-browser": "node build-browser.js",
68
70
  "prepublishOnly": "npm run build-browser",
69
71
  "release": "git pull && git push origin master --tags && npm publish",
70
72
  "release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
71
73
  "mongo": "node ./tools/repl.js",
72
74
  "test": "mocha --exit ./test/*.test.js",
73
- "test-tsd": "tsd",
75
+ "test-tsd": "node ./test/types/check-types-filename && tsd",
74
76
  "tdd": "mocha ./test/*.test.js ./test/typescript/main.test.js --inspect --watch --recursive --watch-files ./**/*.js",
75
77
  "test-coverage": "nyc --reporter=html --reporter=text npm test"
76
78
  },
package/tools/repl.js CHANGED
@@ -5,7 +5,7 @@ run().catch(error => {
5
5
  process.exit(-1);
6
6
  });
7
7
 
8
- async function run () {
8
+ async function run() {
9
9
  const ReplSet = require('mongodb-memory-server').MongoMemoryReplSet;
10
10
 
11
11
  // Create new instance
@@ -15,20 +15,20 @@ async function run () {
15
15
  },
16
16
  instanceOpts: [
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
  dbName: 'mongoose_test',
23
23
  replSet: {
24
- name: "rs0",
24
+ name: 'rs0',
25
25
  count: 2,
26
- storageEngine: "wiredTiger",
27
- },
26
+ storageEngine: 'wiredTiger'
27
+ }
28
28
  });
29
29
 
30
30
  await replSet.start();
31
31
  await replSet.waitUntilRunning();
32
- console.log("MongoDB-ReplicaSet is now running.")
33
- console.log(replSet.getUri("mongoose_test"));
32
+ console.log('MongoDB-ReplicaSet is now running.');
33
+ console.log(replSet.getUri('mongoose_test'));
34
34
  }
package/tools/sharded.js CHANGED
@@ -6,7 +6,7 @@ run().catch(error => {
6
6
  });
7
7
 
8
8
 
9
- async function run () {
9
+ async function run() {
10
10
  const Sharded = require('mongodb-topology-manager').Sharded;
11
11
 
12
12
  // Create new instance
@@ -17,13 +17,13 @@ async function run () {
17
17
 
18
18
  await topology.addShard([{
19
19
  options: {
20
- bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`, shardsvr: null
20
+ bind_ip: 'localhost', port: 31000, dbpath: '/data/db/31000', shardsvr: null
21
21
  }
22
22
  }], { replSet: 'rs1' });
23
23
 
24
24
  await topology.addConfigurationServers([{
25
25
  options: {
26
- bind_ip: 'localhost', port: 35000, dbpath: `/data/db/35000`
26
+ bind_ip: 'localhost', port: 35000, dbpath: '/data/db/35000'
27
27
  }
28
28
  }], { replSet: 'rs0' });
29
29
 
@@ -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
+ }