mongodb 4.3.1 → 4.5.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/README.md +7 -6
- package/lib/admin.js +5 -6
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +31 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +29 -20
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +49 -7
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +12 -1
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js +1 -0
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +0 -6
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +111 -86
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +3 -0
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/collection.js +29 -28
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +53 -40
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +64 -42
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +2 -2
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +4 -3
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +13 -13
- package/lib/db.js.map +1 -1
- package/lib/encrypter.js +17 -9
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +99 -48
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +2 -0
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +42 -51
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +9 -2
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +14 -27
- package/lib/mongo_client.js.map +1 -1
- package/lib/operations/add_user.js +8 -1
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +5 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +8 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +5 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +70 -79
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +3 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +5 -0
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +5 -0
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +8 -9
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +10 -42
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +5 -0
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +1 -2
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +1 -3
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +1 -1
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +5 -0
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_concern.js +1 -0
- package/lib/read_concern.js.map +1 -1
- package/lib/sdam/common.js +1 -7
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/events.js +1 -1
- package/lib/sdam/events.js.map +1 -1
- package/lib/sdam/monitor.js +1 -2
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +79 -57
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +16 -33
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +1 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +93 -68
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +21 -97
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +188 -29
- package/package.json +46 -46
- package/src/admin.ts +6 -10
- package/src/bulk/common.ts +42 -14
- package/src/bulk/unordered.ts +1 -1
- package/src/change_stream.ts +58 -42
- package/src/cmap/auth/gssapi.ts +58 -7
- package/src/cmap/auth/mongo_credentials.ts +17 -2
- package/src/cmap/auth/mongocr.ts +1 -1
- package/src/cmap/auth/mongodb_aws.ts +1 -1
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/scram.ts +3 -2
- package/src/cmap/auth/x509.ts +6 -2
- package/src/cmap/commands.ts +3 -0
- package/src/cmap/connect.ts +2 -20
- package/src/cmap/connection.ts +162 -111
- package/src/cmap/errors.ts +2 -2
- package/src/cmap/message_stream.ts +2 -2
- package/src/cmap/stream_description.ts +4 -1
- package/src/collection.ts +37 -33
- package/src/connection_string.ts +77 -45
- package/src/cursor/abstract_cursor.ts +85 -56
- package/src/cursor/aggregation_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +19 -11
- package/src/db.ts +15 -19
- package/src/deps.ts +52 -0
- package/src/encrypter.ts +18 -10
- package/src/error.ts +145 -76
- package/src/gridfs/download.ts +3 -1
- package/src/gridfs/index.ts +51 -68
- package/src/gridfs/upload.ts +12 -12
- package/src/index.ts +10 -1
- package/src/mongo_client.ts +19 -41
- package/src/operations/add_user.ts +14 -3
- package/src/operations/aggregate.ts +15 -5
- package/src/operations/bulk_write.ts +6 -2
- package/src/operations/collections.ts +6 -2
- package/src/operations/command.ts +23 -8
- package/src/operations/common_functions.ts +8 -1
- package/src/operations/count.ts +6 -2
- package/src/operations/count_documents.ts +5 -1
- package/src/operations/create_collection.ts +6 -2
- package/src/operations/delete.ts +19 -13
- package/src/operations/distinct.ts +6 -2
- package/src/operations/drop.ts +12 -4
- package/src/operations/estimated_document_count.ts +11 -3
- package/src/operations/eval.ts +6 -2
- package/src/operations/execute_operation.ts +102 -101
- package/src/operations/find.ts +9 -5
- package/src/operations/find_and_modify.ts +21 -2
- package/src/operations/get_more.ts +20 -6
- package/src/operations/indexes.ts +54 -36
- package/src/operations/insert.ts +20 -6
- package/src/operations/is_capped.ts +6 -2
- package/src/operations/list_collections.ts +24 -59
- package/src/operations/list_databases.ts +13 -3
- package/src/operations/map_reduce.ts +7 -6
- package/src/operations/operation.ts +10 -9
- package/src/operations/options_operation.ts +6 -2
- package/src/operations/profiling_level.ts +6 -2
- package/src/operations/remove_user.ts +6 -2
- package/src/operations/rename.ts +7 -3
- package/src/operations/run_command.ts +6 -2
- package/src/operations/set_profiling_level.ts +6 -2
- package/src/operations/stats.ts +12 -4
- package/src/operations/update.ts +21 -9
- package/src/operations/validate_collection.ts +6 -2
- package/src/read_concern.ts +1 -0
- package/src/sdam/common.ts +0 -6
- package/src/sdam/events.ts +2 -2
- package/src/sdam/monitor.ts +4 -5
- package/src/sdam/server.ts +95 -90
- package/src/sdam/topology.ts +9 -53
- package/src/sdam/topology_description.ts +1 -3
- package/src/sessions.ts +108 -78
- package/src/utils.ts +38 -118
- package/tsconfig.json +40 -0
- package/mongodb.ts34.d.ts +0 -5649
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,16 +8,9 @@
|
|
|
8
8
|
"src",
|
|
9
9
|
"etc/prepare.js",
|
|
10
10
|
"mongodb.d.ts",
|
|
11
|
-
"
|
|
11
|
+
"tsconfig.json"
|
|
12
12
|
],
|
|
13
13
|
"types": "mongodb.d.ts",
|
|
14
|
-
"typesVersions": {
|
|
15
|
-
"<=4.0.2": {
|
|
16
|
-
"mongodb.d.ts": [
|
|
17
|
-
"mongodb.ts34.d.ts"
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
14
|
"repository": {
|
|
22
15
|
"type": "git",
|
|
23
16
|
"url": "git@github.com:mongodb/node-mongodb-native.git"
|
|
@@ -32,55 +25,57 @@
|
|
|
32
25
|
"email": "dbx-node@mongodb.com"
|
|
33
26
|
},
|
|
34
27
|
"dependencies": {
|
|
35
|
-
"bson": "^4.6.
|
|
28
|
+
"bson": "^4.6.2",
|
|
36
29
|
"denque": "^2.0.1",
|
|
37
|
-
"mongodb-connection-string-url": "^2.
|
|
38
|
-
"socks": "^2.6.
|
|
30
|
+
"mongodb-connection-string-url": "^2.5.2",
|
|
31
|
+
"socks": "^2.6.2"
|
|
39
32
|
},
|
|
40
33
|
"devDependencies": {
|
|
34
|
+
"@iarna/toml": "^2.2.5",
|
|
41
35
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
42
|
-
"@microsoft/api-extractor": "^7.
|
|
36
|
+
"@microsoft/api-extractor": "^7.20.0",
|
|
43
37
|
"@microsoft/tsdoc-config": "^0.15.2",
|
|
44
38
|
"@types/chai": "^4.3.0",
|
|
45
39
|
"@types/chai-subset": "^1.3.3",
|
|
40
|
+
"@types/express": "^4.17.13",
|
|
46
41
|
"@types/kerberos": "^1.1.1",
|
|
47
|
-
"@types/mocha": "^9.
|
|
48
|
-
"@types/node": "^17.0.
|
|
42
|
+
"@types/mocha": "^9.1.0",
|
|
43
|
+
"@types/node": "^17.0.23",
|
|
49
44
|
"@types/saslprep": "^1.0.1",
|
|
50
45
|
"@types/semver": "^7.3.9",
|
|
51
|
-
"@types/sinon": "^10.0.
|
|
46
|
+
"@types/sinon": "^10.0.11",
|
|
52
47
|
"@types/whatwg-url": "^8.2.1",
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
54
|
-
"@typescript-eslint/parser": "^5.
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^5.17.0",
|
|
49
|
+
"@typescript-eslint/parser": "^5.17.0",
|
|
55
50
|
"bluebird": "^3.7.2",
|
|
56
|
-
"chai": "^4.3.
|
|
51
|
+
"chai": "^4.3.6",
|
|
57
52
|
"chai-subset": "^1.6.0",
|
|
58
53
|
"chalk": "^4.1.2",
|
|
59
|
-
"
|
|
60
|
-
"eslint": "^8.
|
|
61
|
-
"eslint-config-prettier": "^8.3.0",
|
|
54
|
+
"eslint": "^8.12.0",
|
|
55
|
+
"eslint-config-prettier": "^8.5.0",
|
|
62
56
|
"eslint-plugin-import": "^2.25.4",
|
|
63
57
|
"eslint-plugin-prettier": "^4.0.0",
|
|
64
58
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
65
59
|
"eslint-plugin-tsdoc": "^0.2.14",
|
|
60
|
+
"express": "^4.17.3",
|
|
66
61
|
"js-yaml": "^4.1.0",
|
|
67
62
|
"lodash.camelcase": "^4.3.0",
|
|
68
|
-
"mocha": "^9.
|
|
63
|
+
"mocha": "^9.2.2",
|
|
69
64
|
"mocha-sinon": "^2.1.2",
|
|
70
65
|
"nyc": "^15.1.0",
|
|
71
|
-
"prettier": "^2.
|
|
66
|
+
"prettier": "^2.6.1",
|
|
72
67
|
"rimraf": "^3.0.2",
|
|
73
68
|
"semver": "^7.3.5",
|
|
74
|
-
"sinon": "^
|
|
69
|
+
"sinon": "^13.0.1",
|
|
75
70
|
"sinon-chai": "^3.7.0",
|
|
76
71
|
"source-map-support": "^0.5.21",
|
|
77
72
|
"standard-version": "^9.3.2",
|
|
78
|
-
"ts-node": "^10.
|
|
79
|
-
"tsd": "^0.
|
|
80
|
-
"typescript": "^4.
|
|
73
|
+
"ts-node": "^10.7.0",
|
|
74
|
+
"tsd": "^0.20.0",
|
|
75
|
+
"typescript": "^4.6.3",
|
|
81
76
|
"typescript-cached-transpile": "^0.0.6",
|
|
82
77
|
"xml2js": "^0.4.23",
|
|
83
|
-
"yargs": "^17.
|
|
78
|
+
"yargs": "^17.4.0"
|
|
84
79
|
},
|
|
85
80
|
"license": "Apache-2.0",
|
|
86
81
|
"engines": {
|
|
@@ -95,32 +90,37 @@
|
|
|
95
90
|
},
|
|
96
91
|
"scripts": {
|
|
97
92
|
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
|
|
98
|
-
"build:ts": "
|
|
99
|
-
"build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*'
|
|
100
|
-
"build:docs": "
|
|
93
|
+
"build:ts": "node ./node_modules/typescript/bin/tsc",
|
|
94
|
+
"build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*'",
|
|
95
|
+
"build:docs": "./etc/docs/build.ts",
|
|
96
|
+
"build:typedoc": "typedoc",
|
|
101
97
|
"check:bench": "node test/benchmarks/driverBench",
|
|
102
98
|
"check:coverage": "nyc npm run test:all",
|
|
99
|
+
"check:integration-coverage": "nyc npm run check:test",
|
|
103
100
|
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
|
|
104
101
|
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
|
|
105
102
|
"check:tsd": "tsd --version && tsd",
|
|
106
|
-
"check:dts": "./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
|
|
107
|
-
"check:test": "mocha --
|
|
108
|
-
"check:unit": "mocha test/unit
|
|
109
|
-
"check:ts": "./node_modules/typescript/bin/tsc -v && ./node_modules/typescript/bin/tsc --noEmit",
|
|
110
|
-
"check:atlas": "mocha --config
|
|
111
|
-
"check:adl": "mocha --
|
|
112
|
-
"check:aws": "mocha --
|
|
113
|
-
"check:ocsp": "mocha --config
|
|
114
|
-
"check:kerberos": "mocha --config
|
|
115
|
-
"check:tls": "mocha --config
|
|
116
|
-
"check:ldap": "mocha --config
|
|
117
|
-
"check:socks5": "mocha --config
|
|
118
|
-
"check:csfle": "mocha --
|
|
103
|
+
"check:dts": "node ./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
|
|
104
|
+
"check:test": "mocha --config test/mocha_mongodb.json test/integration",
|
|
105
|
+
"check:unit": "mocha test/unit",
|
|
106
|
+
"check:ts": "node ./node_modules/typescript/bin/tsc -v && node ./node_modules/typescript/bin/tsc --noEmit",
|
|
107
|
+
"check:atlas": "mocha --config test/manual/mocharc.json test/manual/atlas_connectivity.test.js",
|
|
108
|
+
"check:adl": "mocha --config test/mocha_mongodb.json test/manual/atlas-data-lake-testing",
|
|
109
|
+
"check:aws": "mocha --config test/mocha_mongodb.json test/integration/auth/mongodb_aws.test.js",
|
|
110
|
+
"check:ocsp": "mocha --config test/manual/mocharc.json test/manual/ocsp_support.test.js",
|
|
111
|
+
"check:kerberos": "mocha --config test/manual/mocharc.json test/manual/kerberos.test.js",
|
|
112
|
+
"check:tls": "mocha --config test/manual/mocharc.json test/manual/tls_support.test.js",
|
|
113
|
+
"check:ldap": "mocha --config test/manual/mocharc.json test/manual/ldap.test.js",
|
|
114
|
+
"check:socks5": "mocha --config test/manual/mocharc.json test/manual/socks5.test.ts",
|
|
115
|
+
"check:csfle": "mocha --config test/mocha_mongodb.json test/integration/client-side-encryption",
|
|
119
116
|
"check:snappy": "mocha test/unit/assorted/snappy.test.js",
|
|
117
|
+
"fix:eslint": "npm run check:eslint -- --fix",
|
|
120
118
|
"prepare": "node etc/prepare.js",
|
|
119
|
+
"preview:docs": "ts-node etc/docs/preview.ts",
|
|
121
120
|
"release": "standard-version -i HISTORY.md",
|
|
122
121
|
"test": "npm run check:lint && npm run test:all",
|
|
123
|
-
"test:all": "npm run check:unit && npm run check:test"
|
|
122
|
+
"test:all": "npm run check:unit && npm run check:test",
|
|
123
|
+
"update:docs": "npm run build:docs -- --yes"
|
|
124
124
|
},
|
|
125
125
|
"tsd": {
|
|
126
126
|
"directory": "test/types",
|
package/src/admin.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
ValidateCollectionOperation,
|
|
15
15
|
ValidateCollectionOptions
|
|
16
16
|
} from './operations/validate_collection';
|
|
17
|
-
import { Callback
|
|
17
|
+
import type { Callback } from './utils';
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
20
|
export interface AdminPrivate {
|
|
@@ -83,7 +83,7 @@ export class Admin {
|
|
|
83
83
|
options = Object.assign({ dbName: 'admin' }, options);
|
|
84
84
|
|
|
85
85
|
return executeOperation(
|
|
86
|
-
|
|
86
|
+
this.s.db,
|
|
87
87
|
new RunCommandOperation(this.s.db, command, options),
|
|
88
88
|
callback
|
|
89
89
|
);
|
|
@@ -207,7 +207,7 @@ export class Admin {
|
|
|
207
207
|
options = Object.assign({ dbName: 'admin' }, options);
|
|
208
208
|
|
|
209
209
|
return executeOperation(
|
|
210
|
-
|
|
210
|
+
this.s.db,
|
|
211
211
|
new AddUserOperation(this.s.db, username, password, options),
|
|
212
212
|
callback
|
|
213
213
|
);
|
|
@@ -233,7 +233,7 @@ export class Admin {
|
|
|
233
233
|
options = Object.assign({ dbName: 'admin' }, options);
|
|
234
234
|
|
|
235
235
|
return executeOperation(
|
|
236
|
-
|
|
236
|
+
this.s.db,
|
|
237
237
|
new RemoveUserOperation(this.s.db, username, options),
|
|
238
238
|
callback
|
|
239
239
|
);
|
|
@@ -263,7 +263,7 @@ export class Admin {
|
|
|
263
263
|
options = options ?? {};
|
|
264
264
|
|
|
265
265
|
return executeOperation(
|
|
266
|
-
|
|
266
|
+
this.s.db,
|
|
267
267
|
new ValidateCollectionOperation(this, collectionName, options),
|
|
268
268
|
callback
|
|
269
269
|
);
|
|
@@ -286,11 +286,7 @@ export class Admin {
|
|
|
286
286
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
287
287
|
options = options ?? {};
|
|
288
288
|
|
|
289
|
-
return executeOperation(
|
|
290
|
-
getTopology(this.s.db),
|
|
291
|
-
new ListDatabasesOperation(this.s.db, options),
|
|
292
|
-
callback
|
|
293
|
-
);
|
|
289
|
+
return executeOperation(this.s.db, new ListDatabasesOperation(this.s.db, options), callback);
|
|
294
290
|
}
|
|
295
291
|
|
|
296
292
|
/**
|
package/src/bulk/common.ts
CHANGED
|
@@ -20,14 +20,15 @@ import type { CollationOptions, CommandOperationOptions } from '../operations/co
|
|
|
20
20
|
import { DeleteOperation, DeleteStatement, makeDeleteStatement } from '../operations/delete';
|
|
21
21
|
import { executeOperation } from '../operations/execute_operation';
|
|
22
22
|
import { InsertOperation } from '../operations/insert';
|
|
23
|
-
import
|
|
23
|
+
import { AbstractOperation, Hint } from '../operations/operation';
|
|
24
24
|
import { makeUpdateStatement, UpdateOperation, UpdateStatement } from '../operations/update';
|
|
25
25
|
import { PromiseProvider } from '../promise_provider';
|
|
26
|
+
import type { Server } from '../sdam/server';
|
|
26
27
|
import type { Topology } from '../sdam/topology';
|
|
28
|
+
import type { ClientSession } from '../sessions';
|
|
27
29
|
import {
|
|
28
30
|
applyRetryableWrites,
|
|
29
31
|
Callback,
|
|
30
|
-
executeLegacyOperation,
|
|
31
32
|
getTopology,
|
|
32
33
|
hasAtomicOperators,
|
|
33
34
|
MongoDBNamespace,
|
|
@@ -286,9 +287,7 @@ export class BulkWriteResult {
|
|
|
286
287
|
|
|
287
288
|
/** Returns a specific write error object */
|
|
288
289
|
getWriteErrorAt(index: number): WriteError | undefined {
|
|
289
|
-
|
|
290
|
-
return this.result.writeErrors[index];
|
|
291
|
-
}
|
|
290
|
+
return index < this.result.writeErrors.length ? this.result.writeErrors[index] : undefined;
|
|
292
291
|
}
|
|
293
292
|
|
|
294
293
|
/** Retrieve all write errors */
|
|
@@ -656,19 +655,19 @@ function executeCommands(
|
|
|
656
655
|
try {
|
|
657
656
|
if (isInsertBatch(batch)) {
|
|
658
657
|
executeOperation(
|
|
659
|
-
bulkOperation.s.
|
|
658
|
+
bulkOperation.s.collection,
|
|
660
659
|
new InsertOperation(bulkOperation.s.namespace, batch.operations, finalOptions),
|
|
661
660
|
resultHandler
|
|
662
661
|
);
|
|
663
662
|
} else if (isUpdateBatch(batch)) {
|
|
664
663
|
executeOperation(
|
|
665
|
-
bulkOperation.s.
|
|
664
|
+
bulkOperation.s.collection,
|
|
666
665
|
new UpdateOperation(bulkOperation.s.namespace, batch.operations, finalOptions),
|
|
667
666
|
resultHandler
|
|
668
667
|
);
|
|
669
668
|
} else if (isDeleteBatch(batch)) {
|
|
670
669
|
executeOperation(
|
|
671
|
-
bulkOperation.s.
|
|
670
|
+
bulkOperation.s.collection,
|
|
672
671
|
new DeleteOperation(bulkOperation.s.namespace, batch.operations, finalOptions),
|
|
673
672
|
resultHandler
|
|
674
673
|
);
|
|
@@ -732,7 +731,7 @@ export class MongoBulkWriteError extends MongoServerError {
|
|
|
732
731
|
Object.assign(this, error);
|
|
733
732
|
}
|
|
734
733
|
|
|
735
|
-
get name(): string {
|
|
734
|
+
override get name(): string {
|
|
736
735
|
return 'MongoBulkWriteError';
|
|
737
736
|
}
|
|
738
737
|
|
|
@@ -921,6 +920,34 @@ export interface BulkWriteOptions extends CommandOperationOptions {
|
|
|
921
920
|
keepGoing?: boolean;
|
|
922
921
|
/** Force server to assign _id values instead of driver. */
|
|
923
922
|
forceServerObjectId?: boolean;
|
|
923
|
+
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
924
|
+
let?: Document;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* TODO(NODE-4063)
|
|
929
|
+
* BulkWrites merge complexity is implemented in executeCommands
|
|
930
|
+
* This provides a vehicle to treat bulkOperations like any other operation (hence "shim")
|
|
931
|
+
* We would like this logic to simply live inside the BulkWriteOperation class
|
|
932
|
+
* @internal
|
|
933
|
+
*/
|
|
934
|
+
class BulkWriteShimOperation extends AbstractOperation {
|
|
935
|
+
bulkOperation: BulkOperationBase;
|
|
936
|
+
constructor(bulkOperation: BulkOperationBase, options: BulkWriteOptions) {
|
|
937
|
+
super(options);
|
|
938
|
+
this.bulkOperation = bulkOperation;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
execute(server: Server, session: ClientSession | undefined, callback: Callback<any>): void {
|
|
942
|
+
if (this.options.session == null) {
|
|
943
|
+
// An implicit session could have been created by 'executeOperation'
|
|
944
|
+
// So if we stick it on finalOptions here, each bulk operation
|
|
945
|
+
// will use this same session, it'll be passed in the same way
|
|
946
|
+
// an explicit session would be
|
|
947
|
+
this.options.session = session;
|
|
948
|
+
}
|
|
949
|
+
return executeCommands(this.bulkOperation, this.options, callback);
|
|
950
|
+
}
|
|
924
951
|
}
|
|
925
952
|
|
|
926
953
|
/** @public */
|
|
@@ -1256,17 +1283,16 @@ export abstract class BulkOperationBase {
|
|
|
1256
1283
|
|
|
1257
1284
|
this.s.executed = true;
|
|
1258
1285
|
const finalOptions = { ...this.s.options, ...options };
|
|
1259
|
-
|
|
1286
|
+
const operation = new BulkWriteShimOperation(this, finalOptions);
|
|
1287
|
+
|
|
1288
|
+
return executeOperation(this.s.collection, operation, callback);
|
|
1260
1289
|
}
|
|
1261
1290
|
|
|
1262
1291
|
/**
|
|
1263
1292
|
* Handles the write error before executing commands
|
|
1264
1293
|
* @internal
|
|
1265
1294
|
*/
|
|
1266
|
-
handleWriteError(
|
|
1267
|
-
callback: Callback<BulkWriteResult>,
|
|
1268
|
-
writeResult: BulkWriteResult
|
|
1269
|
-
): boolean | undefined {
|
|
1295
|
+
handleWriteError(callback: Callback<BulkWriteResult>, writeResult: BulkWriteResult): boolean {
|
|
1270
1296
|
if (this.s.bulkResult.writeErrors.length > 0) {
|
|
1271
1297
|
const msg = this.s.bulkResult.writeErrors[0].errmsg
|
|
1272
1298
|
? this.s.bulkResult.writeErrors[0].errmsg
|
|
@@ -1291,6 +1317,8 @@ export abstract class BulkOperationBase {
|
|
|
1291
1317
|
callback(new MongoBulkWriteError(writeConcernError, writeResult));
|
|
1292
1318
|
return true;
|
|
1293
1319
|
}
|
|
1320
|
+
|
|
1321
|
+
return false;
|
|
1294
1322
|
}
|
|
1295
1323
|
|
|
1296
1324
|
abstract addToOperationsList(
|
package/src/bulk/unordered.ts
CHANGED
|
@@ -13,7 +13,7 @@ export class UnorderedBulkOperation extends BulkOperationBase {
|
|
|
13
13
|
super(collection, options, false);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
handleWriteError(callback: Callback, writeResult: BulkWriteResult): boolean
|
|
16
|
+
override handleWriteError(callback: Callback, writeResult: BulkWriteResult): boolean {
|
|
17
17
|
if (this.s.batches.length) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
package/src/change_stream.ts
CHANGED
|
@@ -45,10 +45,21 @@ const kClosed = Symbol('closed');
|
|
|
45
45
|
/** @internal */
|
|
46
46
|
const kMode = Symbol('mode');
|
|
47
47
|
|
|
48
|
-
const CHANGE_STREAM_OPTIONS = [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const CHANGE_STREAM_OPTIONS = [
|
|
49
|
+
'resumeAfter',
|
|
50
|
+
'startAfter',
|
|
51
|
+
'startAtOperationTime',
|
|
52
|
+
'fullDocument'
|
|
53
|
+
] as const;
|
|
54
|
+
|
|
55
|
+
const CURSOR_OPTIONS = [
|
|
56
|
+
'batchSize',
|
|
57
|
+
'maxAwaitTimeMS',
|
|
58
|
+
'collation',
|
|
59
|
+
'readPreference',
|
|
60
|
+
'comment',
|
|
61
|
+
...CHANGE_STREAM_OPTIONS
|
|
62
|
+
] as const;
|
|
52
63
|
|
|
53
64
|
const CHANGE_DOMAIN_TYPES = {
|
|
54
65
|
COLLECTION: Symbol('Collection'),
|
|
@@ -68,6 +79,8 @@ export interface ResumeOptions {
|
|
|
68
79
|
maxAwaitTimeMS?: number;
|
|
69
80
|
collation?: CollationOptions;
|
|
70
81
|
readPreference?: ReadPreference;
|
|
82
|
+
resumeAfter?: ResumeToken;
|
|
83
|
+
startAfter?: ResumeToken;
|
|
71
84
|
}
|
|
72
85
|
|
|
73
86
|
/**
|
|
@@ -94,7 +107,7 @@ export interface PipeOptions {
|
|
|
94
107
|
* @public
|
|
95
108
|
*/
|
|
96
109
|
export interface ChangeStreamOptions extends AggregateOptions {
|
|
97
|
-
/** Allowed values:
|
|
110
|
+
/** Allowed values: 'updateLookup'. When set to 'updateLookup', the change stream will include both a delta describing the changes to the document, as well as a copy of the entire document that was changed from some time after the change occurred. */
|
|
98
111
|
fullDocument?: string;
|
|
99
112
|
/** The maximum amount of time for the server to wait on new documents to satisfy a change stream query. */
|
|
100
113
|
maxAwaitTimeMS?: number;
|
|
@@ -144,7 +157,7 @@ export interface ChangeStreamDocument<TSchema extends Document = Document> {
|
|
|
144
157
|
* this will contain all the components of the shard key in order,
|
|
145
158
|
* followed by the _id if the _id isn’t part of the shard key.
|
|
146
159
|
*/
|
|
147
|
-
documentKey?: InferIdType<TSchema
|
|
160
|
+
documentKey?: { _id: InferIdType<TSchema> };
|
|
148
161
|
|
|
149
162
|
/**
|
|
150
163
|
* Only present for ops of type ‘update’.
|
|
@@ -398,7 +411,7 @@ export class ChangeStream<TSchema extends Document = Document> extends TypedEven
|
|
|
398
411
|
export interface ChangeStreamCursorOptions extends AbstractCursorOptions {
|
|
399
412
|
startAtOperationTime?: OperationTime;
|
|
400
413
|
resumeAfter?: ResumeToken;
|
|
401
|
-
startAfter?:
|
|
414
|
+
startAfter?: ResumeToken;
|
|
402
415
|
}
|
|
403
416
|
|
|
404
417
|
/** @internal */
|
|
@@ -446,22 +459,18 @@ export class ChangeStreamCursor<TSchema extends Document = Document> extends Abs
|
|
|
446
459
|
}
|
|
447
460
|
|
|
448
461
|
get resumeOptions(): ResumeOptions {
|
|
449
|
-
const result =
|
|
450
|
-
for (const optionName of CURSOR_OPTIONS) {
|
|
451
|
-
if (Reflect.has(this.options, optionName)) {
|
|
452
|
-
Reflect.set(result, optionName, Reflect.get(this.options, optionName));
|
|
453
|
-
}
|
|
454
|
-
}
|
|
462
|
+
const result: ResumeOptions = applyKnownOptions(this.options, CURSOR_OPTIONS);
|
|
455
463
|
|
|
456
464
|
if (this.resumeToken || this.startAtOperationTime) {
|
|
457
|
-
['resumeAfter', 'startAfter', 'startAtOperationTime']
|
|
458
|
-
Reflect.deleteProperty(result, key)
|
|
459
|
-
|
|
465
|
+
for (const key of ['resumeAfter', 'startAfter', 'startAtOperationTime']) {
|
|
466
|
+
Reflect.deleteProperty(result, key);
|
|
467
|
+
}
|
|
460
468
|
|
|
461
469
|
if (this.resumeToken) {
|
|
462
470
|
const resumeKey =
|
|
463
471
|
this.options.startAfter && !this.hasReceived ? 'startAfter' : 'resumeAfter';
|
|
464
|
-
|
|
472
|
+
|
|
473
|
+
result[resumeKey] = this.resumeToken;
|
|
465
474
|
} else if (this.startAtOperationTime && maxWireVersion(this.server) >= 7) {
|
|
466
475
|
result.startAtOperationTime = this.startAtOperationTime;
|
|
467
476
|
}
|
|
@@ -503,7 +512,7 @@ export class ChangeStreamCursor<TSchema extends Document = Document> extends Abs
|
|
|
503
512
|
session
|
|
504
513
|
});
|
|
505
514
|
|
|
506
|
-
executeOperation(
|
|
515
|
+
executeOperation(session, aggregateOperation, (err, response) => {
|
|
507
516
|
if (err || response == null) {
|
|
508
517
|
return callback(err);
|
|
509
518
|
}
|
|
@@ -528,7 +537,7 @@ export class ChangeStreamCursor<TSchema extends Document = Document> extends Abs
|
|
|
528
537
|
});
|
|
529
538
|
}
|
|
530
539
|
|
|
531
|
-
_getMore(batchSize: number, callback: Callback): void {
|
|
540
|
+
override _getMore(batchSize: number, callback: Callback): void {
|
|
532
541
|
super._getMore(batchSize, (err, response) => {
|
|
533
542
|
if (err) {
|
|
534
543
|
return callback(err);
|
|
@@ -549,7 +558,7 @@ const CHANGE_STREAM_EVENTS = [
|
|
|
549
558
|
ChangeStream.CLOSE
|
|
550
559
|
];
|
|
551
560
|
|
|
552
|
-
function setIsEmitter<TSchema>(changeStream: ChangeStream<TSchema>): void {
|
|
561
|
+
function setIsEmitter<TSchema extends Document>(changeStream: ChangeStream<TSchema>): void {
|
|
553
562
|
if (changeStream[kMode] === 'iterator') {
|
|
554
563
|
// TODO(NODE-3485): Replace with MongoChangeStreamModeError
|
|
555
564
|
throw new MongoAPIError(
|
|
@@ -559,7 +568,7 @@ function setIsEmitter<TSchema>(changeStream: ChangeStream<TSchema>): void {
|
|
|
559
568
|
changeStream[kMode] = 'emitter';
|
|
560
569
|
}
|
|
561
570
|
|
|
562
|
-
function setIsIterator<TSchema>(changeStream: ChangeStream<TSchema>): void {
|
|
571
|
+
function setIsIterator<TSchema extends Document>(changeStream: ChangeStream<TSchema>): void {
|
|
563
572
|
if (changeStream[kMode] === 'emitter') {
|
|
564
573
|
// TODO(NODE-3485): Replace with MongoChangeStreamModeError
|
|
565
574
|
throw new MongoAPIError(
|
|
@@ -568,25 +577,25 @@ function setIsIterator<TSchema>(changeStream: ChangeStream<TSchema>): void {
|
|
|
568
577
|
}
|
|
569
578
|
changeStream[kMode] = 'iterator';
|
|
570
579
|
}
|
|
580
|
+
|
|
571
581
|
/**
|
|
572
582
|
* Create a new change stream cursor based on self's configuration
|
|
573
583
|
* @internal
|
|
574
584
|
*/
|
|
575
|
-
function createChangeStreamCursor<TSchema>(
|
|
585
|
+
function createChangeStreamCursor<TSchema extends Document>(
|
|
576
586
|
changeStream: ChangeStream<TSchema>,
|
|
577
|
-
options: ChangeStreamOptions
|
|
587
|
+
options: ChangeStreamOptions | ResumeOptions
|
|
578
588
|
): ChangeStreamCursor<TSchema> {
|
|
579
|
-
const changeStreamStageOptions
|
|
580
|
-
applyKnownOptions(changeStreamStageOptions, options, CHANGE_STREAM_OPTIONS);
|
|
589
|
+
const changeStreamStageOptions = applyKnownOptions(options, CHANGE_STREAM_OPTIONS);
|
|
581
590
|
if (changeStream.type === CHANGE_DOMAIN_TYPES.CLUSTER) {
|
|
582
591
|
changeStreamStageOptions.allChangesForCluster = true;
|
|
583
592
|
}
|
|
584
|
-
|
|
585
593
|
const pipeline = [{ $changeStream: changeStreamStageOptions } as Document].concat(
|
|
586
594
|
changeStream.pipeline
|
|
587
595
|
);
|
|
588
596
|
|
|
589
|
-
const cursorOptions = applyKnownOptions(
|
|
597
|
+
const cursorOptions: ChangeStreamCursorOptions = applyKnownOptions(options, CURSOR_OPTIONS);
|
|
598
|
+
|
|
590
599
|
const changeStreamCursor = new ChangeStreamCursor<TSchema>(
|
|
591
600
|
getTopology(changeStream.parent),
|
|
592
601
|
changeStream.namespace,
|
|
@@ -605,16 +614,17 @@ function createChangeStreamCursor<TSchema>(
|
|
|
605
614
|
return changeStreamCursor;
|
|
606
615
|
}
|
|
607
616
|
|
|
608
|
-
function applyKnownOptions(
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
617
|
+
function applyKnownOptions(source: Document, options: ReadonlyArray<string>) {
|
|
618
|
+
const result: Document = {};
|
|
619
|
+
|
|
620
|
+
for (const option of options) {
|
|
621
|
+
if (option in source) {
|
|
622
|
+
result[option] = source[option];
|
|
612
623
|
}
|
|
613
|
-
}
|
|
624
|
+
}
|
|
614
625
|
|
|
615
|
-
return
|
|
626
|
+
return result;
|
|
616
627
|
}
|
|
617
|
-
|
|
618
628
|
interface TopologyWaitOptions {
|
|
619
629
|
start?: number;
|
|
620
630
|
timeout?: number;
|
|
@@ -648,8 +658,8 @@ function waitForTopologyConnected(
|
|
|
648
658
|
}, 500); // this is an arbitrary wait time to allow SDAM to transition
|
|
649
659
|
}
|
|
650
660
|
|
|
651
|
-
function closeWithError<
|
|
652
|
-
changeStream: ChangeStream<
|
|
661
|
+
function closeWithError<TSchema extends Document>(
|
|
662
|
+
changeStream: ChangeStream<TSchema>,
|
|
653
663
|
error: AnyError,
|
|
654
664
|
callback?: Callback
|
|
655
665
|
): void {
|
|
@@ -660,7 +670,7 @@ function closeWithError<T>(
|
|
|
660
670
|
changeStream.close(() => callback && callback(error));
|
|
661
671
|
}
|
|
662
672
|
|
|
663
|
-
function streamEvents<TSchema>(
|
|
673
|
+
function streamEvents<TSchema extends Document>(
|
|
664
674
|
changeStream: ChangeStream<TSchema>,
|
|
665
675
|
cursor: ChangeStreamCursor<TSchema>
|
|
666
676
|
): void {
|
|
@@ -671,7 +681,7 @@ function streamEvents<TSchema>(
|
|
|
671
681
|
stream.on('error', error => processError(changeStream, error));
|
|
672
682
|
}
|
|
673
683
|
|
|
674
|
-
function endStream<TSchema>(changeStream: ChangeStream<TSchema>): void {
|
|
684
|
+
function endStream<TSchema extends Document>(changeStream: ChangeStream<TSchema>): void {
|
|
675
685
|
const cursorStream = changeStream[kCursorStream];
|
|
676
686
|
if (cursorStream) {
|
|
677
687
|
['data', 'close', 'end', 'error'].forEach(event => cursorStream.removeAllListeners(event));
|
|
@@ -681,7 +691,7 @@ function endStream<TSchema>(changeStream: ChangeStream<TSchema>): void {
|
|
|
681
691
|
changeStream[kCursorStream] = undefined;
|
|
682
692
|
}
|
|
683
693
|
|
|
684
|
-
function processNewChange<TSchema>(
|
|
694
|
+
function processNewChange<TSchema extends Document>(
|
|
685
695
|
changeStream: ChangeStream<TSchema>,
|
|
686
696
|
change: Nullable<ChangeStreamDocument<TSchema>>,
|
|
687
697
|
callback?: Callback<ChangeStreamDocument<TSchema>>
|
|
@@ -718,7 +728,7 @@ function processNewChange<TSchema>(
|
|
|
718
728
|
return callback(undefined, change);
|
|
719
729
|
}
|
|
720
730
|
|
|
721
|
-
function processError<TSchema>(
|
|
731
|
+
function processError<TSchema extends Document>(
|
|
722
732
|
changeStream: ChangeStream<TSchema>,
|
|
723
733
|
error: AnyError,
|
|
724
734
|
callback?: Callback
|
|
@@ -786,7 +796,10 @@ function processError<TSchema>(
|
|
|
786
796
|
*
|
|
787
797
|
* @param changeStream - the parent ChangeStream
|
|
788
798
|
*/
|
|
789
|
-
function getCursor<T>(
|
|
799
|
+
function getCursor<T extends Document>(
|
|
800
|
+
changeStream: ChangeStream<T>,
|
|
801
|
+
callback: Callback<ChangeStreamCursor<T>>
|
|
802
|
+
) {
|
|
790
803
|
if (changeStream[kClosed]) {
|
|
791
804
|
// TODO(NODE-3485): Replace with MongoChangeStreamClosedError
|
|
792
805
|
callback(new MongoAPIError(CHANGESTREAM_CLOSED_ERROR));
|
|
@@ -809,7 +822,10 @@ function getCursor<T>(changeStream: ChangeStream<T>, callback: Callback<ChangeSt
|
|
|
809
822
|
* @param changeStream - the parent ChangeStream
|
|
810
823
|
* @param err - error getting a new cursor
|
|
811
824
|
*/
|
|
812
|
-
function processResumeQueue<TSchema>(
|
|
825
|
+
function processResumeQueue<TSchema extends Document>(
|
|
826
|
+
changeStream: ChangeStream<TSchema>,
|
|
827
|
+
err?: Error
|
|
828
|
+
) {
|
|
813
829
|
while (changeStream[kResumeQueue].length) {
|
|
814
830
|
const request = changeStream[kResumeQueue].pop();
|
|
815
831
|
if (!request) break; // Should never occur but TS can't use the length check in the while condition
|