mongoose 6.9.0 → 6.9.2
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/README.md +2 -2
- package/dist/browser.umd.js +1 -1
- package/lib/aggregate.js +41 -42
- package/lib/connection.js +6 -6
- package/lib/cursor/AggregationCursor.js +1 -1
- package/lib/cursor/QueryCursor.js +1 -1
- package/lib/document.js +12 -12
- package/lib/drivers/node-mongodb-native/collection.js +1 -1
- package/lib/error/index.js +21 -10
- package/lib/error/serverSelection.js +1 -1
- package/lib/helpers/document/applyDefaults.js +14 -3
- package/lib/helpers/query/cast$expr.js +1 -1
- package/lib/helpers/query/castUpdate.js +0 -12
- package/lib/index.js +30 -7
- package/lib/model.js +61 -61
- package/lib/query.js +142 -141
- package/lib/schema/SubdocumentPath.js +1 -1
- package/lib/schema/operators/text.js +1 -1
- package/lib/schema/uuid.js +3 -3
- package/lib/schema.js +2 -1
- package/lib/schematype.js +1 -1
- package/lib/types/array/index.js +1 -1
- package/lib/types/array/methods/index.js +4 -3
- package/lib/types/buffer.js +1 -1
- package/lib/virtualtype.js +1 -1
- package/package.json +12 -10
- package/types/aggregate.d.ts +4 -67
- package/types/connection.d.ts +4 -4
- package/types/error.d.ts +5 -0
- package/types/expressions.d.ts +154 -153
- package/types/index.d.ts +3 -3
- package/types/models.d.ts +3 -3
- package/types/mongooseoptions.d.ts +1 -1
- package/types/pipelinestage.d.ts +39 -35
- package/types/query.d.ts +10 -10
- package/types/schematypes.d.ts +1 -1
- package/types/session.d.ts +4 -4
|
@@ -111,7 +111,7 @@ function _createConstructor(schema, baseClass) {
|
|
|
111
111
|
/**
|
|
112
112
|
* Special case for when users use a common location schema to represent
|
|
113
113
|
* locations for use with $geoWithin.
|
|
114
|
-
* https://
|
|
114
|
+
* https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/
|
|
115
115
|
*
|
|
116
116
|
* @param {Object} val
|
|
117
117
|
* @api private
|
|
@@ -11,7 +11,7 @@ const castString = require('../../cast/string');
|
|
|
11
11
|
* @param {Any} val value to cast
|
|
12
12
|
* @param {String} [path] path to associate with any errors that occured
|
|
13
13
|
* @return {Object} casted object
|
|
14
|
-
* @see https://
|
|
14
|
+
* @see https://www.mongodb.com/docs/manual/reference/operator/query/text/
|
|
15
15
|
* @api private
|
|
16
16
|
*/
|
|
17
17
|
|
package/lib/schema/uuid.js
CHANGED
|
@@ -23,7 +23,7 @@ const Binary = MongooseBuffer.Binary;
|
|
|
23
23
|
|
|
24
24
|
function hex2buffer(hex) {
|
|
25
25
|
// use buffer built-in function to convert from hex-string to buffer
|
|
26
|
-
const buff = Buffer.from(hex, 'hex');
|
|
26
|
+
const buff = hex != null && Buffer.from(hex, 'hex');
|
|
27
27
|
return buff;
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -36,7 +36,7 @@ function hex2buffer(hex) {
|
|
|
36
36
|
|
|
37
37
|
function binary2hex(buf) {
|
|
38
38
|
// use buffer built-in function to convert from buffer to hex-string
|
|
39
|
-
const hex = buf.toString('hex');
|
|
39
|
+
const hex = buf != null && buf.toString('hex');
|
|
40
40
|
return hex;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -67,7 +67,7 @@ function stringToBinary(uuidStr) {
|
|
|
67
67
|
function binaryToString(uuidBin) {
|
|
68
68
|
// i(hasezoey) dont quite know why, but "uuidBin" may sometimes also be the already processed string
|
|
69
69
|
let hex;
|
|
70
|
-
if (typeof uuidBin !== 'string') {
|
|
70
|
+
if (typeof uuidBin !== 'string' && uuidBin != null) {
|
|
71
71
|
hex = binary2hex(uuidBin);
|
|
72
72
|
const uuidStr = hex.substring(0, 8) + '-' + hex.substring(8, 8 + 4) + '-' + hex.substring(12, 12 + 4) + '-' + hex.substring(16, 16 + 4) + '-' + hex.substring(20, 20 + 12);
|
|
73
73
|
return uuidStr;
|
package/lib/schema.js
CHANGED
|
@@ -61,7 +61,7 @@ let id = 0;
|
|
|
61
61
|
* - [_id](/docs/guide.html#_id): bool - defaults to true
|
|
62
62
|
* - [minimize](/docs/guide.html#minimize): bool - controls [document#toObject](#document_Document-toObject) behavior when called manually - defaults to true
|
|
63
63
|
* - [read](/docs/guide.html#read): string
|
|
64
|
-
* - [writeConcern](/docs/guide.html#writeConcern): object - defaults to null, use to override [the MongoDB server's default write concern settings](https://
|
|
64
|
+
* - [writeConcern](/docs/guide.html#writeConcern): object - defaults to null, use to override [the MongoDB server's default write concern settings](https://www.mongodb.com/docs/manual/reference/write-concern/)
|
|
65
65
|
* - [shardKey](/docs/guide.html#shardKey): object - defaults to `null`
|
|
66
66
|
* - [strict](/docs/guide.html#strict): bool - defaults to true
|
|
67
67
|
* - [strictQuery](/docs/guide.html#strictQuery): bool - defaults to false
|
|
@@ -2252,6 +2252,7 @@ function _deletePath(schema, name) {
|
|
|
2252
2252
|
}
|
|
2253
2253
|
|
|
2254
2254
|
/**
|
|
2255
|
+
* Removes the given virtual or virtuals from the schema.
|
|
2255
2256
|
*
|
|
2256
2257
|
* @param {String|Array} path The virutal path(s) to remove.
|
|
2257
2258
|
* @returns {Schema} the Schema instance, or a mongoose error if the virtual does not exist.
|
package/lib/schematype.js
CHANGED
|
@@ -402,7 +402,7 @@ SchemaType.prototype.default = function(val) {
|
|
|
402
402
|
*
|
|
403
403
|
* #### Note:
|
|
404
404
|
*
|
|
405
|
-
* _Indexes are created [in the background](https://
|
|
405
|
+
* _Indexes are created [in the background](https://www.mongodb.com/docs/manual/core/index-creation/#index-creation-background)
|
|
406
406
|
* by default. If `background` is set to `false`, MongoDB will not execute any
|
|
407
407
|
* read/write operations you send until the index build.
|
|
408
408
|
* Specify `background: false` to override Mongoose's default._
|
package/lib/types/array/index.js
CHANGED
|
@@ -24,7 +24,7 @@ const arraySchemaSymbol = require('../../helpers/symbols').arraySchemaSymbol;
|
|
|
24
24
|
* @param {String} path
|
|
25
25
|
* @param {Document} doc parent document
|
|
26
26
|
* @api private
|
|
27
|
-
* @inherits Array
|
|
27
|
+
* @inherits Array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
28
28
|
* @see https://bit.ly/f6CnZU
|
|
29
29
|
*/
|
|
30
30
|
const _basePush = Array.prototype.push;
|
|
@@ -137,12 +137,13 @@ const methods = {
|
|
|
137
137
|
this._markModified();
|
|
138
138
|
|
|
139
139
|
// only allow shifting once
|
|
140
|
-
|
|
140
|
+
const __array = this.__array;
|
|
141
|
+
if (__array._shifted) {
|
|
141
142
|
return;
|
|
142
143
|
}
|
|
143
|
-
|
|
144
|
+
__array._shifted = true;
|
|
144
145
|
|
|
145
|
-
return [].shift.call(
|
|
146
|
+
return [].shift.call(__array);
|
|
146
147
|
},
|
|
147
148
|
|
|
148
149
|
/**
|
package/lib/types/buffer.js
CHANGED
package/lib/virtualtype.js
CHANGED
|
@@ -18,7 +18,7 @@ const utils = require('./utils');
|
|
|
18
18
|
* @param {String|Function} [options.foreignField] the foreign field to populate on if this is a populated virtual.
|
|
19
19
|
* @param {Boolean} [options.justOne=false] by default, a populated virtual is an array. If you set `justOne`, the populated virtual will be a single doc or `null`.
|
|
20
20
|
* @param {Boolean} [options.getters=false] if you set this to `true`, Mongoose will call any custom getters you defined on this virtual
|
|
21
|
-
* @param {Boolean} [options.count=false] if you set this to `true`, `populate()` will set this virtual to the number of populated documents, as opposed to the documents themselves, using [`Query#countDocuments()`](
|
|
21
|
+
* @param {Boolean} [options.count=false] if you set this to `true`, `populate()` will set this virtual to the number of populated documents, as opposed to the documents themselves, using [`Query#countDocuments()`](/docs/api/query.html#query_Query-countDocuments)
|
|
22
22
|
* @param {Object|Function} [options.match=null] add an extra match condition to `populate()`
|
|
23
23
|
* @param {Number} [options.limit=null] add a default `limit` to the `populate()` query
|
|
24
24
|
* @param {Number} [options.skip=null] add a default `skip` to the `populate()` query
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "6.9.
|
|
4
|
+
"version": "6.9.2",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"sift": "16.0.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@babel/core": "7.20.
|
|
31
|
+
"@babel/core": "7.20.12",
|
|
32
32
|
"@babel/preset-env": "7.20.2",
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
34
|
-
"@typescript-eslint/parser": "5.
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "5.50.0",
|
|
34
|
+
"@typescript-eslint/parser": "5.50.0",
|
|
35
35
|
"acquit": "1.2.1",
|
|
36
36
|
"acquit-ignore": "0.2.0",
|
|
37
37
|
"acquit-require": "0.1.1",
|
|
@@ -40,21 +40,22 @@
|
|
|
40
40
|
"babel-loader": "8.2.5",
|
|
41
41
|
"benchmark": "2.1.4",
|
|
42
42
|
"bluebird": "3.7.2",
|
|
43
|
+
"broken-link-checker": "^0.7.8",
|
|
43
44
|
"buffer": "^5.6.0",
|
|
44
45
|
"cheerio": "1.0.0-rc.12",
|
|
45
46
|
"crypto-browserify": "3.12.0",
|
|
46
47
|
"dox": "1.0.0",
|
|
47
|
-
"eslint": "8.
|
|
48
|
+
"eslint": "8.33.0",
|
|
48
49
|
"eslint-plugin-mocha-no-only": "1.1.1",
|
|
49
50
|
"express": "^4.18.1",
|
|
50
51
|
"highlight.js": "11.7.0",
|
|
51
52
|
"lodash.isequal": "4.5.0",
|
|
52
53
|
"lodash.isequalwith": "4.4.0",
|
|
53
|
-
"marked": "4.2.
|
|
54
|
-
"mkdirp": "^1.
|
|
54
|
+
"marked": "4.2.12",
|
|
55
|
+
"mkdirp": "^2.1.3",
|
|
55
56
|
"mocha": "10.2.0",
|
|
56
57
|
"moment": "2.x",
|
|
57
|
-
"mongodb-memory-server": "8.
|
|
58
|
+
"mongodb-memory-server": "8.11.4",
|
|
58
59
|
"ncp": "^2.0.0",
|
|
59
60
|
"nyc": "15.1.0",
|
|
60
61
|
"pug": "3.0.2",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"sinon": "15.0.1",
|
|
63
64
|
"stream-browserify": "3.0.0",
|
|
64
65
|
"tsd": "0.25.0",
|
|
65
|
-
"typescript": "4.9.
|
|
66
|
+
"typescript": "4.9.5",
|
|
66
67
|
"uuid": "9.0.0",
|
|
67
68
|
"webpack": "5.75.0"
|
|
68
69
|
},
|
|
@@ -85,6 +86,7 @@
|
|
|
85
86
|
"docs:view": "node ./scripts/static.js",
|
|
86
87
|
"docs:prepare:publish:stable": "npm run docs:checkout:gh-pages && npm run docs:merge:stable && npm run docs:clean:stable && npm run docs:generate && npm run docs:generate:search",
|
|
87
88
|
"docs:prepare:publish:legacy": "npm run docs:checkout:legacy && npm run docs:merge:legacy && npm run docs:clean:stable && npm run docs:generate && npm run docs:copy:tmp && docs:checkout:gh-pages && docs:copy:tmp:legacy",
|
|
89
|
+
"docs:check-links": "blc http://127.0.0.1:8089 -ro",
|
|
88
90
|
"lint": "eslint .",
|
|
89
91
|
"lint-js": "eslint . --ext .js",
|
|
90
92
|
"lint-ts": "eslint . --ext .ts",
|
|
@@ -94,7 +96,7 @@
|
|
|
94
96
|
"release-legacy": "git pull origin 5.x && git push origin 5.x --tags && npm publish --tag legacy",
|
|
95
97
|
"mongo": "node ./tools/repl.js",
|
|
96
98
|
"test": "mocha --exit ./test/*.test.js",
|
|
97
|
-
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys ./test/deno.js",
|
|
99
|
+
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
|
|
98
100
|
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
|
|
99
101
|
"test-tsd": "node ./test/types/check-types-filename && tsd",
|
|
100
102
|
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
|
package/types/aggregate.d.ts
CHANGED
|
@@ -4,67 +4,7 @@ declare module 'mongoose' {
|
|
|
4
4
|
/** Extract generic type from Aggregate class */
|
|
5
5
|
type AggregateExtract<P> = P extends Aggregate<infer T> ? T : never;
|
|
6
6
|
|
|
7
|
-
interface AggregateOptions extends
|
|
8
|
-
SessionOption {
|
|
9
|
-
/**
|
|
10
|
-
* If true, the MongoDB server will use the hard drive to store data during this aggregation.
|
|
11
|
-
*/
|
|
12
|
-
allowDiskUse?: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Applicable only if you specify the $out or $merge aggregation stages.
|
|
15
|
-
*
|
|
16
|
-
* Enables db.collection.aggregate() to bypass document validation during the operation. This lets you insert documents that do not meet the validation requirements.
|
|
17
|
-
*/
|
|
18
|
-
bypassDocumentValidation?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The BSON-serializer will check if keys are valid
|
|
21
|
-
*/
|
|
22
|
-
collation?: mongodb.CollationOptions;
|
|
23
|
-
/**
|
|
24
|
-
* Users can specify an arbitrary string to help trace the operation through the database profiler, currentOp, and logs.
|
|
25
|
-
*/
|
|
26
|
-
comment?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Specifies the initial batch size for the cursor. The value of the cursor field is a document with the field batchSize.
|
|
29
|
-
*/
|
|
30
|
-
cursor?: { batchSize?: number; };
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Specifies to return the information on the processing of the pipeline. See Return Information on Aggregation Pipeline Operation for an example.
|
|
34
|
-
*
|
|
35
|
-
* Not available in multi-document transactions.
|
|
36
|
-
*/
|
|
37
|
-
explain?: mongodb.ExplainVerbosityLike;
|
|
38
|
-
/**
|
|
39
|
-
* The index to use for the aggregation. The index is on the initial collection/view against which the aggregation is run.
|
|
40
|
-
*/
|
|
41
|
-
hint?: string | AnyObject;
|
|
42
|
-
/**
|
|
43
|
-
* Specifies a document with a list of variables. This allows you to improve command readability by separating the variables from the query text.
|
|
44
|
-
*/
|
|
45
|
-
let?: AnyObject;
|
|
46
|
-
/**
|
|
47
|
-
* 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.
|
|
48
|
-
*
|
|
49
|
-
* @see https://docs.mongodb.com/manual/reference/operator/meta/maxTimeMS/
|
|
50
|
-
*/
|
|
51
|
-
maxTimeMS?: number;
|
|
52
|
-
/**
|
|
53
|
-
* Return BSON filled buffers from operations.
|
|
54
|
-
*/
|
|
55
|
-
raw?: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Specifies the read concern.
|
|
58
|
-
*/
|
|
59
|
-
readConcern?: mongodb.ReadConcernLike;
|
|
60
|
-
/**
|
|
61
|
-
* The preferred read preference.
|
|
62
|
-
*/
|
|
63
|
-
readPreference?: mongodb.ReadPreferenceLike;
|
|
64
|
-
/**
|
|
65
|
-
* Specifies the write concern.
|
|
66
|
-
*/
|
|
67
|
-
writeConcern?: mongodb.WriteConcern;
|
|
7
|
+
interface AggregateOptions extends Omit<mongodb.AggregateOptions, 'session'>, SessionOption {
|
|
68
8
|
[key: string]: any;
|
|
69
9
|
}
|
|
70
10
|
|
|
@@ -171,11 +111,8 @@ declare module 'mongoose' {
|
|
|
171
111
|
*/
|
|
172
112
|
model(): Model<any>;
|
|
173
113
|
|
|
174
|
-
/**
|
|
175
|
-
|
|
176
|
-
* @param arg $near operator contents
|
|
177
|
-
*/
|
|
178
|
-
near(arg: { near?: number[]; distanceField: string; maxDistance?: number; query?: Record<string, any>; includeLocs?: string; num?: number; uniqueDocs?: boolean }): this;
|
|
114
|
+
/** Appends a new $geoNear operator to this aggregate pipeline. */
|
|
115
|
+
near(arg: PipelineStage.GeoNear['$geoNear']): this;
|
|
179
116
|
|
|
180
117
|
/** Returns the current pipeline */
|
|
181
118
|
pipeline(): PipelineStage[];
|
|
@@ -196,7 +133,7 @@ declare module 'mongoose' {
|
|
|
196
133
|
replaceRoot(newRoot: PipelineStage.ReplaceRoot['$replaceRoot']['newRoot'] | string): this;
|
|
197
134
|
|
|
198
135
|
/**
|
|
199
|
-
* Helper for [Atlas Text Search](https://
|
|
136
|
+
* Helper for [Atlas Text Search](https://www.mongodb.com/docs/atlas/atlas-search/tutorial/)'s
|
|
200
137
|
* `$search` stage.
|
|
201
138
|
*/
|
|
202
139
|
search(options: PipelineStage.Search['$search']): this;
|
package/types/connection.d.ts
CHANGED
|
@@ -85,8 +85,8 @@ declare module 'mongoose' {
|
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
87
|
* Helper for `createCollection()`. Will explicitly create the given collection
|
|
88
|
-
* with specified options. Used to create [capped collections](https://
|
|
89
|
-
* and [views](https://
|
|
88
|
+
* with specified options. Used to create [capped collections](https://www.mongodb.com/docs/manual/core/capped-collections/)
|
|
89
|
+
* and [views](https://www.mongodb.com/docs/manual/core/views/) from mongoose.
|
|
90
90
|
*/
|
|
91
91
|
createCollection<T extends AnyObject = AnyObject>(name: string, options: mongodb.CreateCollectionOptions, callback: Callback<mongodb.Collection<T>>): void;
|
|
92
92
|
createCollection<T extends AnyObject = AnyObject>(name: string, callback: Callback<mongodb.Collection<T>>): void;
|
|
@@ -204,8 +204,8 @@ declare module 'mongoose' {
|
|
|
204
204
|
setClient(client: mongodb.MongoClient): this;
|
|
205
205
|
|
|
206
206
|
/**
|
|
207
|
-
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://
|
|
208
|
-
* for benefits like causal consistency, [retryable writes](https://
|
|
207
|
+
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
|
|
208
|
+
* for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
|
|
209
209
|
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
210
210
|
*/
|
|
211
211
|
startSession(options: ClientSessionOptions | undefined | null, callback: Callback<ClientSession>): void;
|
package/types/error.d.ts
CHANGED
|
@@ -129,5 +129,10 @@ declare module 'mongoose' {
|
|
|
129
129
|
|
|
130
130
|
constructor(doc: Document, currentVersion: number, modifiedPaths: Array<string>);
|
|
131
131
|
}
|
|
132
|
+
|
|
133
|
+
export class StrictPopulateError extends MongooseError {
|
|
134
|
+
name: 'StrictPopulateError';
|
|
135
|
+
path: string;
|
|
136
|
+
}
|
|
132
137
|
}
|
|
133
138
|
}
|