mongodb 4.0.0 → 4.1.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 +62 -30
- package/lib/bson.js +1 -0
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +53 -30
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/ordered.js +3 -2
- package/lib/bulk/ordered.js.map +1 -1
- package/lib/bulk/unordered.js +3 -2
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +23 -13
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/auth_provider.js +2 -1
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +5 -4
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +9 -5
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +2 -2
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +32 -32
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js +15 -12
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +2 -2
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +26 -10
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +9 -5
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +23 -9
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +43 -46
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +113 -15
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/connection_pool_events.js +3 -1
- package/lib/cmap/connection_pool_events.js.map +1 -1
- package/lib/cmap/errors.js +3 -3
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/message_stream.js +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/metrics.js +62 -0
- package/lib/cmap/metrics.js.map +1 -0
- package/lib/cmap/stream_description.js +3 -1
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/compression.js +22 -9
- package/lib/cmap/wire_protocol/compression.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -1
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +23 -18
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +76 -30
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +75 -68
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +47 -9
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +53 -13
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +21 -14
- package/lib/db.js.map +1 -1
- package/lib/deps.js +16 -5
- package/lib/deps.js.map +1 -1
- package/lib/encrypter.js +5 -8
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +230 -34
- package/lib/error.js.map +1 -1
- package/lib/explain.js +2 -2
- package/lib/explain.js.map +1 -1
- package/lib/gridfs/download.js +22 -47
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +4 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +13 -21
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +27 -2
- package/lib/index.js.map +1 -1
- package/lib/logger.js +3 -2
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +5 -8
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +2 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +12 -9
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/command.js +5 -7
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +1 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/connect.js +3 -2
- package/lib/operations/connect.js.map +1 -1
- package/lib/operations/count.js +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/delete.js +5 -5
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +2 -2
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/estimated_document_count.js +5 -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 +31 -17
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +13 -9
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +9 -9
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/indexes.js +8 -3
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -3
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js +2 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +6 -3
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/map_reduce.js +1 -1
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +3 -1
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js +2 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js +4 -2
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/set_profiling_level.js +4 -2
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/update.js +12 -12
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +6 -5
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/promise_provider.js +1 -1
- package/lib/promise_provider.js.map +1 -1
- package/lib/read_preference.js +8 -8
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/common.js +12 -10
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/server.js +90 -25
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +9 -4
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +10 -4
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +1 -1
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +42 -21
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +7 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +132 -31
- package/lib/sessions.js.map +1 -1
- package/lib/sort.js +3 -3
- package/lib/sort.js.map +1 -1
- package/lib/transactions.js +15 -7
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +60 -20
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +523 -138
- package/mongodb.ts34.d.ts +480 -141
- package/package.json +44 -48
- package/src/bson.ts +1 -0
- package/src/bulk/common.ts +83 -43
- package/src/bulk/ordered.ts +4 -3
- package/src/bulk/unordered.ts +4 -3
- package/src/change_stream.ts +46 -29
- package/src/cmap/auth/auth_provider.ts +3 -2
- package/src/cmap/auth/gssapi.ts +15 -5
- package/src/cmap/auth/mongo_credentials.ts +22 -8
- package/src/cmap/auth/mongocr.ts +3 -3
- package/src/cmap/auth/mongodb_aws.ts +52 -39
- package/src/cmap/auth/plain.ts +2 -2
- package/src/cmap/auth/scram.ts +23 -13
- package/src/cmap/auth/x509.ts +3 -3
- package/src/cmap/command_monitoring_events.ts +36 -14
- package/src/cmap/commands.ts +12 -6
- package/src/cmap/connect.ts +42 -12
- package/src/cmap/connection.ts +54 -62
- package/src/cmap/connection_pool.ts +141 -20
- package/src/cmap/connection_pool_events.ts +8 -1
- package/src/cmap/errors.ts +3 -4
- package/src/cmap/message_stream.ts +2 -4
- package/src/cmap/metrics.ts +58 -0
- package/src/cmap/stream_description.ts +6 -1
- package/src/cmap/wire_protocol/compression.ts +26 -13
- package/src/cmap/wire_protocol/shared.ts +4 -2
- package/src/collection.ts +75 -70
- package/src/connection_string.ts +97 -34
- package/src/cursor/abstract_cursor.ts +141 -104
- package/src/cursor/aggregation_cursor.ts +34 -20
- package/src/cursor/find_cursor.ts +41 -21
- package/src/db.ts +19 -18
- package/src/deps.ts +110 -22
- package/src/encrypter.ts +6 -12
- package/src/error.ts +264 -48
- package/src/explain.ts +3 -3
- package/src/gridfs/download.ts +48 -53
- package/src/gridfs/index.ts +5 -4
- package/src/gridfs/upload.ts +32 -33
- package/src/index.ts +42 -4
- package/src/logger.ts +6 -3
- package/src/mongo_client.ts +20 -23
- package/src/mongo_types.ts +19 -20
- package/src/operations/add_user.ts +4 -5
- package/src/operations/aggregate.ts +18 -17
- package/src/operations/command.ts +7 -10
- package/src/operations/common_functions.ts +2 -3
- package/src/operations/connect.ts +4 -3
- package/src/operations/count.ts +2 -2
- package/src/operations/count_documents.ts +2 -2
- package/src/operations/delete.ts +8 -6
- package/src/operations/distinct.ts +5 -3
- package/src/operations/estimated_document_count.ts +5 -1
- package/src/operations/eval.ts +1 -1
- package/src/operations/execute_operation.ts +41 -20
- package/src/operations/find.ts +25 -16
- package/src/operations/find_and_modify.ts +12 -10
- package/src/operations/indexes.ts +39 -8
- package/src/operations/insert.ts +7 -4
- package/src/operations/is_capped.ts +3 -2
- package/src/operations/list_collections.ts +9 -6
- package/src/operations/map_reduce.ts +4 -2
- package/src/operations/operation.ts +7 -2
- package/src/operations/options_operation.ts +3 -2
- package/src/operations/profiling_level.ts +5 -3
- package/src/operations/set_profiling_level.ts +9 -3
- package/src/operations/update.ts +17 -13
- package/src/operations/validate_collection.ts +7 -6
- package/src/promise_provider.ts +2 -2
- package/src/read_preference.ts +11 -9
- package/src/sdam/common.ts +11 -9
- package/src/sdam/server.ts +168 -69
- package/src/sdam/server_description.ts +16 -4
- package/src/sdam/server_selection.ts +15 -7
- package/src/sdam/srv_polling.ts +2 -2
- package/src/sdam/topology.ts +67 -36
- package/src/sdam/topology_description.ts +11 -4
- package/src/sessions.ts +194 -37
- package/src/sort.ts +6 -4
- package/src/transactions.ts +18 -9
- package/src/utils.ts +73 -20
- package/HISTORY.md +0 -2993
- package/lib/operations/find_one.js +0 -34
- package/lib/operations/find_one.js.map +0 -1
- package/src/operations/find_one.ts +0 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -31,68 +31,57 @@
|
|
|
31
31
|
"name": "The MongoDB NodeJS Team",
|
|
32
32
|
"email": "dbx-node@mongodb.com"
|
|
33
33
|
},
|
|
34
|
-
"peerOptionalDependencies": {
|
|
35
|
-
"kerberos": "^1.1.0",
|
|
36
|
-
"mongodb-client-encryption": "^1.0.0",
|
|
37
|
-
"snappy": "^6.1.1",
|
|
38
|
-
"bson-ext": "^2.0.0"
|
|
39
|
-
},
|
|
40
34
|
"dependencies": {
|
|
41
|
-
"bson": "^4.
|
|
42
|
-
"denque": "^
|
|
43
|
-
"mongodb-connection-string-url": "^
|
|
35
|
+
"bson": "^4.5.2",
|
|
36
|
+
"denque": "^2.0.1",
|
|
37
|
+
"mongodb-connection-string-url": "^2.0.0"
|
|
44
38
|
},
|
|
45
39
|
"devDependencies": {
|
|
46
40
|
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
|
47
|
-
"@microsoft/api-extractor": "^7.
|
|
41
|
+
"@microsoft/api-extractor": "^7.18.7",
|
|
48
42
|
"@microsoft/tsdoc-config": "^0.15.2",
|
|
49
|
-
"@types/
|
|
50
|
-
"@types/chai": "^4.2.14",
|
|
43
|
+
"@types/chai": "^4.2.21",
|
|
51
44
|
"@types/chai-subset": "^1.3.3",
|
|
52
|
-
"@types/kerberos": "^1.1.
|
|
53
|
-
"@types/mocha": "^
|
|
54
|
-
"@types/node": "^
|
|
55
|
-
"@types/saslprep": "^1.0.
|
|
56
|
-
"@types/semver": "^7.3.
|
|
57
|
-
"@
|
|
58
|
-
"@typescript-eslint/
|
|
59
|
-
"
|
|
45
|
+
"@types/kerberos": "^1.1.1",
|
|
46
|
+
"@types/mocha": "^9.0.0",
|
|
47
|
+
"@types/node": "^16.7.13",
|
|
48
|
+
"@types/saslprep": "^1.0.1",
|
|
49
|
+
"@types/semver": "^7.3.8",
|
|
50
|
+
"@types/whatwg-url": "^8.2.1",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^4.31.0",
|
|
52
|
+
"@typescript-eslint/parser": "^4.31.0",
|
|
53
|
+
"bluebird": "^3.7.2",
|
|
54
|
+
"chai": "^4.3.4",
|
|
60
55
|
"chai-subset": "^1.6.0",
|
|
61
|
-
"chalk": "^4.1.
|
|
56
|
+
"chalk": "^4.1.2",
|
|
62
57
|
"co": "4.6.0",
|
|
63
|
-
"coveralls": "^3.0.11",
|
|
64
58
|
"downlevel-dts": "^0.7.0",
|
|
65
|
-
"eslint": "^7.
|
|
66
|
-
"eslint-config-prettier": "^
|
|
67
|
-
"eslint-plugin-jsdoc": "^
|
|
68
|
-
"eslint-plugin-prettier": "^
|
|
59
|
+
"eslint": "^7.32.0",
|
|
60
|
+
"eslint-config-prettier": "^8.3.0",
|
|
61
|
+
"eslint-plugin-jsdoc": "^36.1.0",
|
|
62
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
69
63
|
"eslint-plugin-tsdoc": "^0.2.14",
|
|
70
|
-
"js-yaml": "^
|
|
71
|
-
"jsdoc": "^3.6.
|
|
64
|
+
"js-yaml": "^4.1.0",
|
|
65
|
+
"jsdoc": "^3.6.7",
|
|
72
66
|
"lodash.camelcase": "^4.3.0",
|
|
73
|
-
"
|
|
74
|
-
"mocha": "^
|
|
75
|
-
"mocha-sinon": "^2.1.0",
|
|
67
|
+
"mocha": "^9.1.1",
|
|
68
|
+
"mocha-sinon": "^2.1.2",
|
|
76
69
|
"mongodb-mock-server": "^2.0.1",
|
|
77
70
|
"nyc": "^15.1.0",
|
|
78
|
-
"prettier": "2.
|
|
71
|
+
"prettier": "^2.3.2",
|
|
79
72
|
"rimraf": "^3.0.2",
|
|
80
|
-
"semver": "^
|
|
81
|
-
"sinon": "^
|
|
82
|
-
"sinon-chai": "^3.
|
|
83
|
-
"snappy": "^6.3.0",
|
|
73
|
+
"semver": "^7.3.5",
|
|
74
|
+
"sinon": "^11.1.2",
|
|
75
|
+
"sinon-chai": "^3.7.0",
|
|
84
76
|
"source-map-support": "^0.5.19",
|
|
85
|
-
"standard-version": "^9.3.
|
|
86
|
-
"
|
|
87
|
-
"ts-node": "^10.0.0",
|
|
77
|
+
"standard-version": "^9.3.1",
|
|
78
|
+
"ts-node": "^10.2.1",
|
|
88
79
|
"tsd": "^0.17.0",
|
|
89
|
-
"typedoc": "^0.21.
|
|
90
|
-
"typescript": "
|
|
80
|
+
"typedoc": "^0.21.9",
|
|
81
|
+
"typescript": "4.3.5",
|
|
91
82
|
"typescript-cached-transpile": "^0.0.6",
|
|
92
|
-
"worker-farm": "^1.5.0",
|
|
93
|
-
"wtfnode": "^0.8.2",
|
|
94
83
|
"xml2js": "^0.4.23",
|
|
95
|
-
"yargs": "^
|
|
84
|
+
"yargs": "^17.1.1"
|
|
96
85
|
},
|
|
97
86
|
"license": "Apache-2.0",
|
|
98
87
|
"engines": {
|
|
@@ -103,7 +92,7 @@
|
|
|
103
92
|
},
|
|
104
93
|
"homepage": "https://github.com/mongodb/node-mongodb-native",
|
|
105
94
|
"optionalDependencies": {
|
|
106
|
-
"saslprep": "^1.0.
|
|
95
|
+
"saslprep": "^1.0.3"
|
|
107
96
|
},
|
|
108
97
|
"scripts": {
|
|
109
98
|
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
|
|
@@ -112,8 +101,9 @@
|
|
|
112
101
|
"build:docs": "typedoc",
|
|
113
102
|
"check:bench": "node test/benchmarks/driverBench",
|
|
114
103
|
"check:coverage": "nyc npm run check:test",
|
|
115
|
-
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint",
|
|
104
|
+
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
|
|
116
105
|
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
|
|
106
|
+
"check:tsd": "tsd --version && tsd",
|
|
117
107
|
"check:dts": "tsc --noEmit mongodb.d.ts && tsd",
|
|
118
108
|
"check:test": "mocha --recursive test/functional test/unit",
|
|
119
109
|
"check:ts": "tsc -v && tsc --noEmit",
|
|
@@ -129,6 +119,12 @@
|
|
|
129
119
|
"test": "npm run check:lint && npm run check:test"
|
|
130
120
|
},
|
|
131
121
|
"tsd": {
|
|
132
|
-
"directory": "test/types"
|
|
122
|
+
"directory": "test/types",
|
|
123
|
+
"compilerOptions": {
|
|
124
|
+
"strict": true,
|
|
125
|
+
"target": "esnext",
|
|
126
|
+
"module": "commonjs",
|
|
127
|
+
"moduleResolution": "node"
|
|
128
|
+
}
|
|
133
129
|
}
|
|
134
130
|
}
|
package/src/bson.ts
CHANGED
package/src/bulk/common.ts
CHANGED
|
@@ -5,7 +5,8 @@ import {
|
|
|
5
5
|
AnyError,
|
|
6
6
|
MONGODB_ERROR_CODES,
|
|
7
7
|
MongoServerError,
|
|
8
|
-
|
|
8
|
+
MongoInvalidArgumentError,
|
|
9
|
+
MongoBatchReExecutionError
|
|
9
10
|
} from '../error';
|
|
10
11
|
import {
|
|
11
12
|
applyRetryableWrites,
|
|
@@ -25,7 +26,10 @@ import type { Collection } from '../collection';
|
|
|
25
26
|
import type { Topology } from '../sdam/topology';
|
|
26
27
|
import type { CommandOperationOptions, CollationOptions } from '../operations/command';
|
|
27
28
|
import type { Hint } from '../operations/operation';
|
|
28
|
-
import type { Filter, OptionalId, UpdateFilter } from '../mongo_types';
|
|
29
|
+
import type { Filter, OneOrMore, OptionalId, UpdateFilter } from '../mongo_types';
|
|
30
|
+
|
|
31
|
+
/** @internal */
|
|
32
|
+
const kServerError = Symbol('serverError');
|
|
29
33
|
|
|
30
34
|
/** @public */
|
|
31
35
|
export const BatchType = Object.freeze({
|
|
@@ -308,9 +312,7 @@ export class BulkWriteResult {
|
|
|
308
312
|
if (i === 0) errmsg = errmsg + ' and ';
|
|
309
313
|
}
|
|
310
314
|
|
|
311
|
-
return new WriteConcernError(
|
|
312
|
-
new MongoServerError({ errmsg: errmsg, code: MONGODB_ERROR_CODES.WriteConcernFailed })
|
|
313
|
-
);
|
|
315
|
+
return new WriteConcernError({ errmsg, code: MONGODB_ERROR_CODES.WriteConcernFailed });
|
|
314
316
|
}
|
|
315
317
|
}
|
|
316
318
|
|
|
@@ -327,34 +329,52 @@ export class BulkWriteResult {
|
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
|
|
332
|
+
/** @public */
|
|
333
|
+
export interface WriteConcernErrorData {
|
|
334
|
+
code: number;
|
|
335
|
+
errmsg: string;
|
|
336
|
+
errInfo?: Document;
|
|
337
|
+
}
|
|
338
|
+
|
|
330
339
|
/**
|
|
331
340
|
* An error representing a failure by the server to apply the requested write concern to the bulk operation.
|
|
332
341
|
* @public
|
|
333
342
|
* @category Error
|
|
334
343
|
*/
|
|
335
344
|
export class WriteConcernError {
|
|
336
|
-
|
|
345
|
+
/** @internal */
|
|
346
|
+
[kServerError]: WriteConcernErrorData;
|
|
337
347
|
|
|
338
|
-
constructor(
|
|
339
|
-
this
|
|
348
|
+
constructor(error: WriteConcernErrorData) {
|
|
349
|
+
this[kServerError] = error;
|
|
340
350
|
}
|
|
341
351
|
|
|
342
352
|
/** Write concern error code. */
|
|
343
353
|
get code(): number | undefined {
|
|
344
|
-
return this.
|
|
354
|
+
return this[kServerError].code;
|
|
345
355
|
}
|
|
346
356
|
|
|
347
357
|
/** Write concern error message. */
|
|
348
|
-
get errmsg(): string {
|
|
349
|
-
return this.
|
|
358
|
+
get errmsg(): string | undefined {
|
|
359
|
+
return this[kServerError].errmsg;
|
|
350
360
|
}
|
|
351
361
|
|
|
352
|
-
|
|
353
|
-
|
|
362
|
+
/** Write concern error info. */
|
|
363
|
+
get errInfo(): Document | undefined {
|
|
364
|
+
return this[kServerError].errInfo;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** @deprecated The `err` prop that contained a MongoServerError has been deprecated. */
|
|
368
|
+
get err(): WriteConcernErrorData {
|
|
369
|
+
return this[kServerError];
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
toJSON(): WriteConcernErrorData {
|
|
373
|
+
return this[kServerError];
|
|
354
374
|
}
|
|
355
375
|
|
|
356
376
|
toString(): string {
|
|
357
|
-
return `WriteConcernError(${this.
|
|
377
|
+
return `WriteConcernError(${this.errmsg})`;
|
|
358
378
|
}
|
|
359
379
|
}
|
|
360
380
|
|
|
@@ -363,6 +383,7 @@ export interface BulkWriteOperationError {
|
|
|
363
383
|
index: number;
|
|
364
384
|
code: number;
|
|
365
385
|
errmsg: string;
|
|
386
|
+
errInfo: Document;
|
|
366
387
|
op: Document | UpdateStatement | DeleteStatement;
|
|
367
388
|
}
|
|
368
389
|
|
|
@@ -393,6 +414,11 @@ export class WriteError {
|
|
|
393
414
|
return this.err.errmsg;
|
|
394
415
|
}
|
|
395
416
|
|
|
417
|
+
/** WriteError details. */
|
|
418
|
+
get errInfo(): Document | undefined {
|
|
419
|
+
return this.err.errInfo;
|
|
420
|
+
}
|
|
421
|
+
|
|
396
422
|
/** Returns the underlying operation that caused the error */
|
|
397
423
|
getOperation(): Document {
|
|
398
424
|
return this.err.op;
|
|
@@ -433,6 +459,7 @@ function mergeBatchResults(
|
|
|
433
459
|
index: 0,
|
|
434
460
|
code: result.code || 0,
|
|
435
461
|
errmsg: result.message,
|
|
462
|
+
errInfo: result.errInfo,
|
|
436
463
|
op: batch.operations[0]
|
|
437
464
|
};
|
|
438
465
|
|
|
@@ -535,6 +562,7 @@ function mergeBatchResults(
|
|
|
535
562
|
index: batch.originalIndexes[result.writeErrors[i].index],
|
|
536
563
|
code: result.writeErrors[i].code,
|
|
537
564
|
errmsg: result.writeErrors[i].errmsg,
|
|
565
|
+
errInfo: result.writeErrors[i].errInfo,
|
|
538
566
|
op: batch.operations[result.writeErrors[i].index]
|
|
539
567
|
};
|
|
540
568
|
|
|
@@ -655,17 +683,12 @@ function handleMongoWriteConcernError(
|
|
|
655
683
|
) {
|
|
656
684
|
mergeBatchResults(batch, bulkResult, undefined, err.result);
|
|
657
685
|
|
|
658
|
-
// TODO: Remove multiple levels of wrapping (NODE-3337)
|
|
659
|
-
const wrappedWriteConcernError = new WriteConcernError(
|
|
660
|
-
new MongoServerError({
|
|
661
|
-
errmsg: err.result?.writeConcernError.errmsg,
|
|
662
|
-
code: err.result?.writeConcernError.result
|
|
663
|
-
})
|
|
664
|
-
);
|
|
665
|
-
|
|
666
686
|
callback(
|
|
667
687
|
new MongoBulkWriteError(
|
|
668
|
-
|
|
688
|
+
{
|
|
689
|
+
message: err.result?.writeConcernError.errmsg,
|
|
690
|
+
code: err.result?.writeConcernError.result
|
|
691
|
+
},
|
|
669
692
|
new BulkWriteResult(bulkResult)
|
|
670
693
|
)
|
|
671
694
|
);
|
|
@@ -678,13 +701,28 @@ function handleMongoWriteConcernError(
|
|
|
678
701
|
*/
|
|
679
702
|
export class MongoBulkWriteError extends MongoServerError {
|
|
680
703
|
result: BulkWriteResult;
|
|
704
|
+
writeErrors: OneOrMore<WriteError> = [];
|
|
705
|
+
err?: WriteConcernError;
|
|
681
706
|
|
|
682
707
|
/** Creates a new MongoBulkWriteError */
|
|
683
|
-
constructor(
|
|
684
|
-
|
|
685
|
-
|
|
708
|
+
constructor(
|
|
709
|
+
error:
|
|
710
|
+
| { message: string; code: number; writeErrors?: WriteError[] }
|
|
711
|
+
| WriteConcernError
|
|
712
|
+
| AnyError,
|
|
713
|
+
result: BulkWriteResult
|
|
714
|
+
) {
|
|
715
|
+
super(error);
|
|
716
|
+
|
|
717
|
+
if (error instanceof WriteConcernError) this.err = error;
|
|
718
|
+
else if (!(error instanceof Error)) {
|
|
719
|
+
this.message = error.message;
|
|
720
|
+
this.code = error.code;
|
|
721
|
+
this.writeErrors = error.writeErrors ?? [];
|
|
722
|
+
}
|
|
686
723
|
|
|
687
724
|
this.result = result;
|
|
725
|
+
Object.assign(this, error);
|
|
688
726
|
}
|
|
689
727
|
|
|
690
728
|
get name(): string {
|
|
@@ -753,7 +791,7 @@ export class FindOperators {
|
|
|
753
791
|
/** Add a single update operation to the bulk operation */
|
|
754
792
|
updateOne(updateDocument: Document): BulkOperationBase {
|
|
755
793
|
if (!hasAtomicOperators(updateDocument)) {
|
|
756
|
-
throw new
|
|
794
|
+
throw new MongoInvalidArgumentError('Update document requires atomic operators');
|
|
757
795
|
}
|
|
758
796
|
|
|
759
797
|
const currentOp = buildCurrentOp(this.bulkOperation);
|
|
@@ -766,7 +804,7 @@ export class FindOperators {
|
|
|
766
804
|
/** Add a replace one operation to the bulk operation */
|
|
767
805
|
replaceOne(replacement: Document): BulkOperationBase {
|
|
768
806
|
if (hasAtomicOperators(replacement)) {
|
|
769
|
-
throw new
|
|
807
|
+
throw new MongoInvalidArgumentError('Replacement document must not use atomic operators');
|
|
770
808
|
}
|
|
771
809
|
|
|
772
810
|
const currentOp = buildCurrentOp(this.bulkOperation);
|
|
@@ -1049,7 +1087,7 @@ export abstract class BulkOperationBase {
|
|
|
1049
1087
|
*/
|
|
1050
1088
|
find(selector: Document): FindOperators {
|
|
1051
1089
|
if (!selector) {
|
|
1052
|
-
throw new
|
|
1090
|
+
throw new MongoInvalidArgumentError('Bulk find operation must specify a selector');
|
|
1053
1091
|
}
|
|
1054
1092
|
|
|
1055
1093
|
// Save a current selector
|
|
@@ -1083,7 +1121,7 @@ export abstract class BulkOperationBase {
|
|
|
1083
1121
|
if ('replaceOne' in op || 'updateOne' in op || 'updateMany' in op) {
|
|
1084
1122
|
if ('replaceOne' in op) {
|
|
1085
1123
|
if ('q' in op.replaceOne) {
|
|
1086
|
-
throw new
|
|
1124
|
+
throw new MongoInvalidArgumentError('Raw operations are not allowed');
|
|
1087
1125
|
}
|
|
1088
1126
|
const updateStatement = makeUpdateStatement(
|
|
1089
1127
|
op.replaceOne.filter,
|
|
@@ -1091,35 +1129,35 @@ export abstract class BulkOperationBase {
|
|
|
1091
1129
|
{ ...op.replaceOne, multi: false }
|
|
1092
1130
|
);
|
|
1093
1131
|
if (hasAtomicOperators(updateStatement.u)) {
|
|
1094
|
-
throw new
|
|
1132
|
+
throw new MongoInvalidArgumentError('Replacement document must not use atomic operators');
|
|
1095
1133
|
}
|
|
1096
1134
|
return this.addToOperationsList(BatchType.UPDATE, updateStatement);
|
|
1097
1135
|
}
|
|
1098
1136
|
|
|
1099
1137
|
if ('updateOne' in op) {
|
|
1100
1138
|
if ('q' in op.updateOne) {
|
|
1101
|
-
throw new
|
|
1139
|
+
throw new MongoInvalidArgumentError('Raw operations are not allowed');
|
|
1102
1140
|
}
|
|
1103
1141
|
const updateStatement = makeUpdateStatement(op.updateOne.filter, op.updateOne.update, {
|
|
1104
1142
|
...op.updateOne,
|
|
1105
1143
|
multi: false
|
|
1106
1144
|
});
|
|
1107
1145
|
if (!hasAtomicOperators(updateStatement.u)) {
|
|
1108
|
-
throw new
|
|
1146
|
+
throw new MongoInvalidArgumentError('Update document requires atomic operators');
|
|
1109
1147
|
}
|
|
1110
1148
|
return this.addToOperationsList(BatchType.UPDATE, updateStatement);
|
|
1111
1149
|
}
|
|
1112
1150
|
|
|
1113
1151
|
if ('updateMany' in op) {
|
|
1114
1152
|
if ('q' in op.updateMany) {
|
|
1115
|
-
throw new
|
|
1153
|
+
throw new MongoInvalidArgumentError('Raw operations are not allowed');
|
|
1116
1154
|
}
|
|
1117
1155
|
const updateStatement = makeUpdateStatement(op.updateMany.filter, op.updateMany.update, {
|
|
1118
1156
|
...op.updateMany,
|
|
1119
1157
|
multi: true
|
|
1120
1158
|
});
|
|
1121
1159
|
if (!hasAtomicOperators(updateStatement.u)) {
|
|
1122
|
-
throw new
|
|
1160
|
+
throw new MongoInvalidArgumentError('Update document requires atomic operators');
|
|
1123
1161
|
}
|
|
1124
1162
|
return this.addToOperationsList(BatchType.UPDATE, updateStatement);
|
|
1125
1163
|
}
|
|
@@ -1127,7 +1165,7 @@ export abstract class BulkOperationBase {
|
|
|
1127
1165
|
|
|
1128
1166
|
if ('deleteOne' in op) {
|
|
1129
1167
|
if ('q' in op.deleteOne) {
|
|
1130
|
-
throw new
|
|
1168
|
+
throw new MongoInvalidArgumentError('Raw operations are not allowed');
|
|
1131
1169
|
}
|
|
1132
1170
|
return this.addToOperationsList(
|
|
1133
1171
|
BatchType.DELETE,
|
|
@@ -1137,7 +1175,7 @@ export abstract class BulkOperationBase {
|
|
|
1137
1175
|
|
|
1138
1176
|
if ('deleteMany' in op) {
|
|
1139
1177
|
if ('q' in op.deleteMany) {
|
|
1140
|
-
throw new
|
|
1178
|
+
throw new MongoInvalidArgumentError('Raw operations are not allowed');
|
|
1141
1179
|
}
|
|
1142
1180
|
return this.addToOperationsList(
|
|
1143
1181
|
BatchType.DELETE,
|
|
@@ -1146,7 +1184,7 @@ export abstract class BulkOperationBase {
|
|
|
1146
1184
|
}
|
|
1147
1185
|
|
|
1148
1186
|
// otherwise an unknown operation was provided
|
|
1149
|
-
throw new
|
|
1187
|
+
throw new MongoInvalidArgumentError(
|
|
1150
1188
|
'bulkWrite only supports insertOne, updateOne, updateMany, deleteOne, deleteMany'
|
|
1151
1189
|
);
|
|
1152
1190
|
}
|
|
@@ -1180,7 +1218,7 @@ export abstract class BulkOperationBase {
|
|
|
1180
1218
|
options = options ?? {};
|
|
1181
1219
|
|
|
1182
1220
|
if (this.s.executed) {
|
|
1183
|
-
return handleEarlyError(new
|
|
1221
|
+
return handleEarlyError(new MongoBatchReExecutionError(), callback);
|
|
1184
1222
|
}
|
|
1185
1223
|
|
|
1186
1224
|
const writeConcern = WriteConcern.fromOptions(options);
|
|
@@ -1198,7 +1236,9 @@ export abstract class BulkOperationBase {
|
|
|
1198
1236
|
}
|
|
1199
1237
|
// If we have no operations in the bulk raise an error
|
|
1200
1238
|
if (this.s.batches.length === 0) {
|
|
1201
|
-
const emptyBatchError = new
|
|
1239
|
+
const emptyBatchError = new MongoInvalidArgumentError(
|
|
1240
|
+
'Invalid BulkOperation, Batch cannot be empty'
|
|
1241
|
+
);
|
|
1202
1242
|
return handleEarlyError(emptyBatchError, callback);
|
|
1203
1243
|
}
|
|
1204
1244
|
|
|
@@ -1222,11 +1262,11 @@ export abstract class BulkOperationBase {
|
|
|
1222
1262
|
|
|
1223
1263
|
callback(
|
|
1224
1264
|
new MongoBulkWriteError(
|
|
1225
|
-
|
|
1265
|
+
{
|
|
1226
1266
|
message: msg,
|
|
1227
1267
|
code: this.s.bulkResult.writeErrors[0].code,
|
|
1228
1268
|
writeErrors: this.s.bulkResult.writeErrors
|
|
1229
|
-
}
|
|
1269
|
+
},
|
|
1230
1270
|
writeResult
|
|
1231
1271
|
)
|
|
1232
1272
|
);
|
|
@@ -1236,7 +1276,7 @@ export abstract class BulkOperationBase {
|
|
|
1236
1276
|
|
|
1237
1277
|
const writeConcernError = writeResult.getWriteConcernError();
|
|
1238
1278
|
if (writeConcernError) {
|
|
1239
|
-
callback(new MongoBulkWriteError(
|
|
1279
|
+
callback(new MongoBulkWriteError(writeConcernError, writeResult));
|
|
1240
1280
|
return true;
|
|
1241
1281
|
}
|
|
1242
1282
|
}
|
package/src/bulk/ordered.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { Document } from '../bson';
|
|
|
4
4
|
import type { Collection } from '../collection';
|
|
5
5
|
import type { UpdateStatement } from '../operations/update';
|
|
6
6
|
import type { DeleteStatement } from '../operations/delete';
|
|
7
|
-
import {
|
|
7
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
10
10
|
export class OrderedBulkOperation extends BulkOperationBase {
|
|
@@ -26,7 +26,8 @@ export class OrderedBulkOperation extends BulkOperationBase {
|
|
|
26
26
|
|
|
27
27
|
// Throw error if the doc is bigger than the max BSON size
|
|
28
28
|
if (bsonSize >= this.s.maxBsonObjectSize)
|
|
29
|
-
|
|
29
|
+
// TODO(NODE-3483): Change this to MongoBSONError
|
|
30
|
+
throw new MongoInvalidArgumentError(
|
|
30
31
|
`Document is larger than the maximum size ${this.s.maxBsonObjectSize}`
|
|
31
32
|
);
|
|
32
33
|
|
|
@@ -68,7 +69,7 @@ export class OrderedBulkOperation extends BulkOperationBase {
|
|
|
68
69
|
|
|
69
70
|
// We have an array of documents
|
|
70
71
|
if (Array.isArray(document)) {
|
|
71
|
-
throw new
|
|
72
|
+
throw new MongoInvalidArgumentError('Operation passed in cannot be an Array');
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
this.s.currentBatch.originalIndexes.push(this.s.currentIndex);
|
package/src/bulk/unordered.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { Document } from '../bson';
|
|
|
5
5
|
import type { Collection } from '../collection';
|
|
6
6
|
import type { UpdateStatement } from '../operations/update';
|
|
7
7
|
import type { DeleteStatement } from '../operations/delete';
|
|
8
|
-
import {
|
|
8
|
+
import { MongoInvalidArgumentError } from '../error';
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export class UnorderedBulkOperation extends BulkOperationBase {
|
|
@@ -36,7 +36,8 @@ export class UnorderedBulkOperation extends BulkOperationBase {
|
|
|
36
36
|
|
|
37
37
|
// Throw error if the doc is bigger than the max BSON size
|
|
38
38
|
if (bsonSize >= this.s.maxBsonObjectSize) {
|
|
39
|
-
|
|
39
|
+
// TODO(NODE-3483): Change this to MongoBSONError
|
|
40
|
+
throw new MongoInvalidArgumentError(
|
|
40
41
|
`Document is larger than the maximum size ${this.s.maxBsonObjectSize}`
|
|
41
42
|
);
|
|
42
43
|
}
|
|
@@ -79,7 +80,7 @@ export class UnorderedBulkOperation extends BulkOperationBase {
|
|
|
79
80
|
|
|
80
81
|
// We have an array of documents
|
|
81
82
|
if (Array.isArray(document)) {
|
|
82
|
-
throw new
|
|
83
|
+
throw new MongoInvalidArgumentError('Operation passed in cannot be an Array');
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
this.s.currentBatch.operations.push(document);
|