mongoose 6.2.9 → 6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/browser.umd.js +2 -1693
- package/lib/aggregate.js +59 -67
- package/lib/browser.js +4 -4
- package/lib/connection.js +21 -21
- package/lib/cursor/AggregationCursor.js +2 -2
- package/lib/cursor/ChangeStream.js +42 -2
- package/lib/cursor/QueryCursor.js +5 -3
- package/lib/document.js +39 -46
- package/lib/error/eachAsyncMultiError.js +41 -0
- package/lib/error/index.js +2 -2
- 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/markArraySubdocsPopulated.js +1 -1
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/query/applyGlobalOption.js +29 -0
- package/lib/helpers/query/castUpdate.js +3 -1
- package/lib/helpers/update/applyTimestampsToChildren.js +2 -2
- package/lib/helpers/update/applyTimestampsToUpdate.js +0 -1
- package/lib/index.js +33 -26
- package/lib/model.js +88 -90
- package/lib/options/SchemaArrayOptions.js +2 -2
- package/lib/options/SchemaBufferOptions.js +1 -1
- package/lib/options/SchemaDateOptions.js +2 -2
- package/lib/options/SchemaDocumentArrayOptions.js +3 -3
- package/lib/options/SchemaMapOptions.js +2 -2
- package/lib/options/SchemaNumberOptions.js +3 -3
- package/lib/options/SchemaObjectIdOptions.js +2 -2
- package/lib/options/SchemaStringOptions.js +1 -1
- package/lib/options/SchemaSubdocumentOptions.js +2 -2
- package/lib/options/SchemaTypeOptions.js +3 -3
- package/lib/query.js +273 -249
- package/lib/schema/SubdocumentPath.js +4 -3
- package/lib/schema/array.js +2 -2
- package/lib/schema/boolean.js +4 -4
- package/lib/schema/buffer.js +3 -3
- package/lib/schema/date.js +7 -7
- package/lib/schema/decimal128.js +2 -2
- package/lib/schema/documentarray.js +3 -3
- package/lib/schema/mixed.js +2 -2
- package/lib/schema/number.js +6 -6
- package/lib/schema/objectid.js +4 -7
- package/lib/schema/string.js +38 -16
- package/lib/schema.js +144 -30
- package/lib/schematype.js +75 -68
- package/lib/types/ArraySubdocument.js +1 -1
- package/lib/types/DocumentArray/methods/index.js +2 -2
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +13 -13
- package/lib/types/buffer.js +1 -1
- package/lib/types/decimal128.js +1 -1
- package/lib/types/objectid.js +1 -1
- package/lib/types/subdocument.js +31 -2
- package/lib/validoptions.js +1 -0
- package/lib/virtualtype.js +3 -3
- package/package.json +19 -13
- package/tools/repl.js +2 -1
- package/types/aggregate.d.ts +223 -0
- package/types/cursor.d.ts +10 -4
- package/types/index.d.ts +194 -209
- package/types/mongooseoptions.d.ts +10 -4
- package/lib/helpers/query/applyGlobalMaxTimeMS.js +0 -15
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.0",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"bson": "^4.2.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",
|
|
@@ -30,47 +30,53 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/core": "7.17.8",
|
|
32
32
|
"@babel/preset-env": "7.16.11",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
34
|
-
"@typescript-eslint/parser": "5.
|
|
35
|
-
"acquit": "1.
|
|
36
|
-
"acquit-ignore": "0.2.
|
|
37
|
-
"acquit-require": "0.1.
|
|
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
|
+
"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
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.12.0",
|
|
45
47
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
46
|
-
"highlight.js": "
|
|
48
|
+
"highlight.js": "11.5.0",
|
|
47
49
|
"lodash.isequal": "4.5.0",
|
|
48
50
|
"lodash.isequalwith": "4.4.0",
|
|
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",
|
|
59
|
+
"sinon": "13.0.0",
|
|
60
|
+
"stream-browserify": "3.0.0",
|
|
57
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",
|
|
70
76
|
"release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
|
|
71
77
|
"mongo": "node ./tools/repl.js",
|
|
72
78
|
"test": "mocha --exit ./test/*.test.js",
|
|
73
|
-
"test-tsd": "tsd",
|
|
79
|
+
"test-tsd": "node ./test/types/check-types-filename && tsd",
|
|
74
80
|
"tdd": "mocha ./test/*.test.js ./test/typescript/main.test.js --inspect --watch --recursive --watch-files ./**/*.js",
|
|
75
81
|
"test-coverage": "nyc --reporter=html --reporter=text npm test"
|
|
76
82
|
},
|
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: {
|
|
@@ -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
|
+
}
|
package/types/cursor.d.ts
CHANGED
|
@@ -3,6 +3,12 @@ import stream = require('stream');
|
|
|
3
3
|
declare module 'mongoose' {
|
|
4
4
|
type CursorFlag = 'tailable' | 'oplogReplay' | 'noCursorTimeout' | 'awaitData' | 'partial';
|
|
5
5
|
|
|
6
|
+
interface EachAsyncOptions {
|
|
7
|
+
parallel?: number;
|
|
8
|
+
batchSize?: number;
|
|
9
|
+
continueOnError?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
class Cursor<DocType = any, Options = never> extends stream.Readable {
|
|
7
13
|
[Symbol.asyncIterator](): AsyncIterableIterator<DocType>;
|
|
8
14
|
|
|
@@ -25,10 +31,10 @@ declare module 'mongoose' {
|
|
|
25
31
|
* will wait for the promise to resolve before iterating on to the next one.
|
|
26
32
|
* Returns a promise that resolves when done.
|
|
27
33
|
*/
|
|
28
|
-
eachAsync(fn: (doc: DocType[]) => any, options:
|
|
29
|
-
eachAsync(fn: (doc: DocType) => any, options:
|
|
30
|
-
eachAsync(fn: (doc: DocType[]) => any, options:
|
|
31
|
-
eachAsync(fn: (doc: DocType) => any, options?:
|
|
34
|
+
eachAsync(fn: (doc: DocType[]) => any, options: EachAsyncOptions & { batchSize: number }, callback: CallbackWithoutResult): void;
|
|
35
|
+
eachAsync(fn: (doc: DocType) => any, options: EachAsyncOptions, callback: CallbackWithoutResult): void;
|
|
36
|
+
eachAsync(fn: (doc: DocType[]) => any, options: EachAsyncOptions & { batchSize: number }): Promise<void>;
|
|
37
|
+
eachAsync(fn: (doc: DocType) => any, options?: EachAsyncOptions): Promise<void>;
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* Registers a transform function which subsequently maps documents retrieved
|