mongodb 4.1.3 → 4.2.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 +15 -14
- package/lib/admin.js +5 -5
- package/lib/admin.js.map +1 -1
- package/lib/bson.js.map +1 -1
- package/lib/bulk/common.js +54 -56
- package/lib/bulk/common.js.map +1 -1
- package/lib/change_stream.js +13 -14
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +1 -1
- package/lib/cmap/auth/gssapi.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 +3 -3
- 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 +5 -5
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +15 -15
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +10 -7
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +2 -2
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +15 -15
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +3 -3
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js +2 -2
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +4 -4
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/cmap/wire_protocol/constants.js +4 -4
- package/lib/collection.js +42 -41
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +73 -45
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +16 -13
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +14 -14
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +23 -23
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +20 -20
- package/lib/db.js.map +1 -1
- package/lib/deps.js +1 -1
- package/lib/deps.js.map +1 -1
- package/lib/error.js +47 -24
- package/lib/error.js.map +1 -1
- package/lib/gridfs/index.js +3 -3
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/logger.js +5 -5
- package/lib/logger.js.map +1 -1
- package/lib/mongo_client.js +7 -7
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_types.js.map +1 -1
- package/lib/operations/add_user.js +3 -3
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +3 -4
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/command.js +7 -3
- 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 +1 -1
- 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/create_collection.js +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +6 -6
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +4 -4
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js +2 -2
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js +2 -2
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/execute_operation.js +24 -7
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +8 -8
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +7 -7
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +28 -0
- package/lib/operations/get_more.js.map +1 -0
- package/lib/operations/indexes.js +14 -14
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +5 -5
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/list_collections.js +12 -7
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +1 -1
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +6 -6
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +4 -2
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/remove_user.js +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +2 -2
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/set_profiling_level.js +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +2 -2
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +12 -12
- package/lib/operations/update.js.map +1 -1
- package/lib/read_preference.js +4 -1
- package/lib/read_preference.js.map +1 -1
- package/lib/sdam/monitor.js +14 -14
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +19 -12
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/server_description.js +3 -3
- package/lib/sdam/server_description.js.map +1 -1
- package/lib/sdam/server_selection.js +36 -1
- package/lib/sdam/server_selection.js.map +1 -1
- package/lib/sdam/srv_polling.js +9 -9
- package/lib/sdam/srv_polling.js.map +1 -1
- package/lib/sdam/topology.js +29 -21
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +34 -12
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +19 -19
- package/lib/sessions.js.map +1 -1
- package/lib/transactions.js.map +1 -1
- package/lib/utils.js +53 -46
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +60 -37
- package/mongodb.ts34.d.ts +61 -37
- package/package.json +26 -30
- package/src/bson.ts +1 -0
- package/src/bulk/common.ts +50 -37
- package/src/change_stream.ts +10 -8
- package/src/cmap/commands.ts +11 -8
- package/src/cmap/connection.ts +1 -0
- package/src/cmap/stream_description.ts +3 -3
- package/src/cmap/wire_protocol/constants.ts +4 -4
- package/src/collection.ts +40 -25
- package/src/connection_string.ts +75 -36
- package/src/cursor/abstract_cursor.ts +9 -11
- package/src/db.ts +5 -6
- package/src/error.ts +51 -23
- package/src/mongo_client.ts +12 -0
- package/src/mongo_types.ts +11 -14
- package/src/operations/aggregate.ts +1 -2
- package/src/operations/command.ts +5 -0
- package/src/operations/create_collection.ts +1 -1
- package/src/operations/execute_operation.ts +22 -2
- package/src/operations/get_more.ts +49 -0
- package/src/operations/list_collections.ts +12 -4
- package/src/operations/operation.ts +5 -1
- package/src/read_preference.ts +4 -1
- package/src/sdam/server.ts +8 -0
- package/src/sdam/server_selection.ts +43 -0
- package/src/sdam/srv_polling.ts +12 -11
- package/src/sdam/topology.ts +27 -10
- package/src/sdam/topology_description.ts +35 -11
- package/src/sessions.ts +2 -1
- package/src/transactions.ts +2 -2
- package/src/utils.ts +67 -56
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"description": "The official MongoDB driver for Node.js",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -32,56 +32,52 @@
|
|
|
32
32
|
"email": "dbx-node@mongodb.com"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"bson": "^4.
|
|
35
|
+
"bson": "^4.6.0",
|
|
36
36
|
"denque": "^2.0.1",
|
|
37
|
-
"mongodb-connection-string-url": "^2.
|
|
37
|
+
"mongodb-connection-string-url": "^2.3.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@istanbuljs/nyc-config-typescript": "^1.0.
|
|
41
|
-
"@microsoft/api-extractor": "^7.18.
|
|
40
|
+
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
41
|
+
"@microsoft/api-extractor": "^7.18.21",
|
|
42
42
|
"@microsoft/tsdoc-config": "^0.15.2",
|
|
43
|
-
"@types/chai": "^4.
|
|
43
|
+
"@types/chai": "^4.3.0",
|
|
44
44
|
"@types/chai-subset": "^1.3.3",
|
|
45
45
|
"@types/kerberos": "^1.1.1",
|
|
46
46
|
"@types/mocha": "^9.0.0",
|
|
47
|
-
"@types/node": "^16.
|
|
47
|
+
"@types/node": "^16.11.12",
|
|
48
48
|
"@types/saslprep": "^1.0.1",
|
|
49
|
-
"@types/semver": "^7.3.
|
|
49
|
+
"@types/semver": "^7.3.9",
|
|
50
|
+
"@types/sinon": "^10.0.6",
|
|
50
51
|
"@types/whatwg-url": "^8.2.1",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
52
|
-
"@typescript-eslint/parser": "^
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.6.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.6.0",
|
|
53
54
|
"bluebird": "^3.7.2",
|
|
54
55
|
"chai": "^4.3.4",
|
|
55
56
|
"chai-subset": "^1.6.0",
|
|
56
57
|
"chalk": "^4.1.2",
|
|
57
|
-
"co": "4.6.0",
|
|
58
58
|
"downlevel-dts": "^0.7.0",
|
|
59
|
-
"eslint": "^
|
|
59
|
+
"eslint": "^8.4.1",
|
|
60
60
|
"eslint-config-prettier": "^8.3.0",
|
|
61
|
-
"eslint-plugin-jsdoc": "^36.1.0",
|
|
62
61
|
"eslint-plugin-prettier": "^4.0.0",
|
|
63
62
|
"eslint-plugin-tsdoc": "^0.2.14",
|
|
64
63
|
"js-yaml": "^4.1.0",
|
|
65
|
-
"jsdoc": "^3.6.7",
|
|
66
64
|
"lodash.camelcase": "^4.3.0",
|
|
67
|
-
"mocha": "^9.1.
|
|
65
|
+
"mocha": "^9.1.3",
|
|
68
66
|
"mocha-sinon": "^2.1.2",
|
|
69
|
-
"mongodb-mock-server": "^2.0.1",
|
|
70
67
|
"nyc": "^15.1.0",
|
|
71
|
-
"prettier": "^2.
|
|
68
|
+
"prettier": "^2.5.1",
|
|
72
69
|
"rimraf": "^3.0.2",
|
|
73
70
|
"semver": "^7.3.5",
|
|
74
|
-
"sinon": "^
|
|
71
|
+
"sinon": "^12.0.1",
|
|
75
72
|
"sinon-chai": "^3.7.0",
|
|
76
|
-
"source-map-support": "^0.5.
|
|
77
|
-
"standard-version": "^9.3.
|
|
78
|
-
"ts-node": "^10.
|
|
79
|
-
"tsd": "^0.
|
|
80
|
-
"
|
|
81
|
-
"typescript": "4.3.5",
|
|
73
|
+
"source-map-support": "^0.5.21",
|
|
74
|
+
"standard-version": "^9.3.2",
|
|
75
|
+
"ts-node": "^10.4.0",
|
|
76
|
+
"tsd": "^0.19.0",
|
|
77
|
+
"typescript": "^4.5.2",
|
|
82
78
|
"typescript-cached-transpile": "^0.0.6",
|
|
83
79
|
"xml2js": "^0.4.23",
|
|
84
|
-
"yargs": "^17.
|
|
80
|
+
"yargs": "^17.3.0"
|
|
85
81
|
},
|
|
86
82
|
"license": "Apache-2.0",
|
|
87
83
|
"engines": {
|
|
@@ -96,7 +92,7 @@
|
|
|
96
92
|
},
|
|
97
93
|
"scripts": {
|
|
98
94
|
"build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
|
|
99
|
-
"build:ts": "rimraf lib && tsc",
|
|
95
|
+
"build:ts": "rimraf lib && ./node_modules/typescript/bin/tsc",
|
|
100
96
|
"build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*' && downlevel-dts mongodb.d.ts mongodb.ts34.d.ts",
|
|
101
97
|
"build:docs": "typedoc",
|
|
102
98
|
"check:bench": "node test/benchmarks/driverBench",
|
|
@@ -104,10 +100,10 @@
|
|
|
104
100
|
"check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
|
|
105
101
|
"check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
|
|
106
102
|
"check:tsd": "tsd --version && tsd",
|
|
107
|
-
"check:dts": "tsc --noEmit mongodb.d.ts && tsd",
|
|
108
|
-
"check:test": "mocha --file test/tools/runner --recursive test/functional",
|
|
103
|
+
"check:dts": "./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
|
|
104
|
+
"check:test": "mocha --file test/tools/runner --recursive test/functional test/integration",
|
|
109
105
|
"check:unit": "mocha --recursive test/unit/",
|
|
110
|
-
"check:ts": "tsc -v && tsc --noEmit",
|
|
106
|
+
"check:ts": "./node_modules/typescript/bin/tsc -v && ./node_modules/typescript/bin/tsc --noEmit",
|
|
111
107
|
"check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
|
|
112
108
|
"check:adl": "mocha --file test/tools/runner test/manual/data_lake.test.js",
|
|
113
109
|
"check:aws": "mocha --file test/tools/runner test/functional/mongodb_aws.test.js",
|
|
@@ -115,7 +111,7 @@
|
|
|
115
111
|
"check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
|
|
116
112
|
"check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
|
|
117
113
|
"check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
|
|
118
|
-
"check:csfle": "mocha --file test/tools/runner test/
|
|
114
|
+
"check:csfle": "mocha --file test/tools/runner test/integration/client-side-encryption",
|
|
119
115
|
"check:snappy": "mocha --file test/tools/runner test/functional/unit_snappy.test.js",
|
|
120
116
|
"prepare": "node etc/prepare.js",
|
|
121
117
|
"release": "standard-version -i HISTORY.md",
|
package/src/bson.ts
CHANGED
package/src/bulk/common.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { PromiseProvider } from '../promise_provider';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Long,
|
|
4
|
+
ObjectId,
|
|
5
|
+
Document,
|
|
6
|
+
BSONSerializeOptions,
|
|
7
|
+
resolveBSONOptions,
|
|
8
|
+
Timestamp
|
|
9
|
+
} from '../bson';
|
|
3
10
|
import {
|
|
4
11
|
MongoWriteConcernError,
|
|
5
12
|
AnyError,
|
|
@@ -26,7 +33,7 @@ import type { Collection } from '../collection';
|
|
|
26
33
|
import type { Topology } from '../sdam/topology';
|
|
27
34
|
import type { CommandOperationOptions, CollationOptions } from '../operations/command';
|
|
28
35
|
import type { Hint } from '../operations/operation';
|
|
29
|
-
import type { Filter, OneOrMore, OptionalId, UpdateFilter } from '../mongo_types';
|
|
36
|
+
import type { Filter, OneOrMore, WithoutId, OptionalId, UpdateFilter } from '../mongo_types';
|
|
30
37
|
|
|
31
38
|
/** @internal */
|
|
32
39
|
const kServerError = Symbol('serverError');
|
|
@@ -72,7 +79,7 @@ export interface ReplaceOneModel<TSchema extends Document = Document> {
|
|
|
72
79
|
/** The filter to limit the replaced document. */
|
|
73
80
|
filter: Filter<TSchema>;
|
|
74
81
|
/** The document with which to replace the matched document. */
|
|
75
|
-
replacement: TSchema
|
|
82
|
+
replacement: WithoutId<TSchema>;
|
|
76
83
|
/** Specifies a collation. */
|
|
77
84
|
collation?: CollationOptions;
|
|
78
85
|
/** The index to use. If specified, then the query system will only consider plans using the hinted index. */
|
|
@@ -433,8 +440,13 @@ export class WriteError {
|
|
|
433
440
|
}
|
|
434
441
|
}
|
|
435
442
|
|
|
443
|
+
/** Converts the number to a Long or returns it. */
|
|
444
|
+
function longOrConvert(value: number | Long | Timestamp): Long | Timestamp {
|
|
445
|
+
return typeof value === 'number' ? Long.fromNumber(value) : value;
|
|
446
|
+
}
|
|
447
|
+
|
|
436
448
|
/** Merges results into shared data structure */
|
|
437
|
-
function mergeBatchResults(
|
|
449
|
+
export function mergeBatchResults(
|
|
438
450
|
batch: Batch,
|
|
439
451
|
bulkResult: BulkResult,
|
|
440
452
|
err?: AnyError,
|
|
@@ -469,42 +481,37 @@ function mergeBatchResults(
|
|
|
469
481
|
return;
|
|
470
482
|
}
|
|
471
483
|
|
|
472
|
-
//
|
|
484
|
+
// The server write command specification states that lastOp is an optional
|
|
485
|
+
// mongod only field that has a type of timestamp. Across various scarce specs
|
|
486
|
+
// where opTime is mentioned, it is an "opaque" object that can have a "ts" and
|
|
487
|
+
// "t" field with Timestamp and Long as their types respectively.
|
|
488
|
+
// The "lastOp" field of the bulk write result is never mentioned in the driver
|
|
489
|
+
// specifications or the bulk write spec, so we should probably just keep its
|
|
490
|
+
// value consistent since it seems to vary.
|
|
491
|
+
// See: https://github.com/mongodb/specifications/blob/master/source/driver-bulk-update.rst#results-object
|
|
473
492
|
if (result.opTime || result.lastOp) {
|
|
474
|
-
|
|
475
|
-
let lastOpTS = null;
|
|
476
|
-
let lastOpT = null;
|
|
477
|
-
|
|
478
|
-
// We have a time stamp
|
|
479
|
-
if (opTime && opTime._bsontype === 'Timestamp') {
|
|
480
|
-
if (bulkResult.opTime == null) {
|
|
481
|
-
bulkResult.opTime = opTime;
|
|
482
|
-
} else if (opTime.greaterThan(bulkResult.opTime)) {
|
|
483
|
-
bulkResult.opTime = opTime;
|
|
484
|
-
}
|
|
485
|
-
} else {
|
|
486
|
-
// Existing TS
|
|
487
|
-
if (bulkResult.opTime) {
|
|
488
|
-
lastOpTS =
|
|
489
|
-
typeof bulkResult.opTime.ts === 'number'
|
|
490
|
-
? Long.fromNumber(bulkResult.opTime.ts)
|
|
491
|
-
: bulkResult.opTime.ts;
|
|
492
|
-
lastOpT =
|
|
493
|
-
typeof bulkResult.opTime.t === 'number'
|
|
494
|
-
? Long.fromNumber(bulkResult.opTime.t)
|
|
495
|
-
: bulkResult.opTime.t;
|
|
496
|
-
}
|
|
493
|
+
let opTime = result.lastOp || result.opTime;
|
|
497
494
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
495
|
+
// If the opTime is a Timestamp, convert it to a consistent format to be
|
|
496
|
+
// able to compare easily. Converting to the object from a timestamp is
|
|
497
|
+
// much more straightforward than the other direction.
|
|
498
|
+
if (opTime._bsontype === 'Timestamp') {
|
|
499
|
+
opTime = { ts: opTime, t: Long.ZERO };
|
|
500
|
+
}
|
|
501
501
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
502
|
+
// If there's no lastOp, just set it.
|
|
503
|
+
if (!bulkResult.opTime) {
|
|
504
|
+
bulkResult.opTime = opTime;
|
|
505
|
+
} else {
|
|
506
|
+
// First compare the ts values and set if the opTimeTS value is greater.
|
|
507
|
+
const lastOpTS = longOrConvert(bulkResult.opTime.ts);
|
|
508
|
+
const opTimeTS = longOrConvert(opTime.ts);
|
|
509
|
+
if (opTimeTS.greaterThan(lastOpTS)) {
|
|
506
510
|
bulkResult.opTime = opTime;
|
|
507
511
|
} else if (opTimeTS.equals(lastOpTS)) {
|
|
512
|
+
// If the ts values are equal, then compare using the t values.
|
|
513
|
+
const lastOpT = longOrConvert(bulkResult.opTime.t);
|
|
514
|
+
const opTimeT = longOrConvert(opTime.t);
|
|
508
515
|
if (opTimeT.greaterThan(lastOpT)) {
|
|
509
516
|
bulkResult.opTime = opTime;
|
|
510
517
|
}
|
|
@@ -1209,9 +1216,15 @@ export abstract class BulkOperationBase {
|
|
|
1209
1216
|
return batches;
|
|
1210
1217
|
}
|
|
1211
1218
|
|
|
1212
|
-
|
|
1219
|
+
execute(options?: BulkWriteOptions): Promise<BulkWriteResult>;
|
|
1220
|
+
execute(callback: Callback<BulkWriteResult>): void;
|
|
1221
|
+
execute(options: BulkWriteOptions | undefined, callback: Callback<BulkWriteResult>): void;
|
|
1222
|
+
execute(
|
|
1223
|
+
options?: BulkWriteOptions | Callback<BulkWriteResult>,
|
|
1224
|
+
callback?: Callback<BulkWriteResult>
|
|
1225
|
+
): Promise<BulkWriteResult> | void;
|
|
1213
1226
|
execute(
|
|
1214
|
-
options?: BulkWriteOptions
|
|
1227
|
+
options?: BulkWriteOptions | Callback<BulkWriteResult>,
|
|
1215
1228
|
callback?: Callback<BulkWriteResult>
|
|
1216
1229
|
): Promise<BulkWriteResult> | void {
|
|
1217
1230
|
if (typeof options === 'function') (callback = options), (options = {});
|
package/src/change_stream.ts
CHANGED
|
@@ -184,23 +184,23 @@ export interface UpdateDescription<TSchema extends Document = Document> {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
/** @public */
|
|
187
|
-
export type ChangeStreamEvents = {
|
|
187
|
+
export type ChangeStreamEvents<TSchema extends Document = Document> = {
|
|
188
188
|
resumeTokenChanged(token: ResumeToken): void;
|
|
189
|
-
init(response:
|
|
190
|
-
more(response?:
|
|
189
|
+
init(response: TSchema): void;
|
|
190
|
+
more(response?: TSchema | undefined): void;
|
|
191
191
|
response(): void;
|
|
192
192
|
end(): void;
|
|
193
193
|
error(error: Error): void;
|
|
194
|
-
change(change: ChangeStreamDocument): void;
|
|
194
|
+
change(change: ChangeStreamDocument<TSchema>): void;
|
|
195
195
|
} & AbstractCursorEvents;
|
|
196
196
|
|
|
197
197
|
/**
|
|
198
198
|
* Creates a new Change Stream instance. Normally created using {@link Collection#watch|Collection.watch()}.
|
|
199
199
|
* @public
|
|
200
200
|
*/
|
|
201
|
-
export class ChangeStream<
|
|
202
|
-
TSchema
|
|
203
|
-
>
|
|
201
|
+
export class ChangeStream<TSchema extends Document = Document> extends TypedEventEmitter<
|
|
202
|
+
ChangeStreamEvents<TSchema>
|
|
203
|
+
> {
|
|
204
204
|
pipeline: Document[];
|
|
205
205
|
options: ChangeStreamOptions;
|
|
206
206
|
parent: MongoClient | Db | Collection;
|
|
@@ -310,7 +310,9 @@ export class ChangeStream<
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
/** Check if there is any document still available in the Change Stream */
|
|
313
|
-
hasNext(
|
|
313
|
+
hasNext(): Promise<boolean>;
|
|
314
|
+
hasNext(callback: Callback<boolean>): void;
|
|
315
|
+
hasNext(callback?: Callback): Promise<boolean> | void {
|
|
314
316
|
setIsIterator(this);
|
|
315
317
|
return maybePromise(callback, cb => {
|
|
316
318
|
getCursor(this, (err, cursor) => {
|
package/src/cmap/commands.ts
CHANGED
|
@@ -469,6 +469,8 @@ export interface MessageHeader {
|
|
|
469
469
|
export interface OpResponseOptions extends BSONSerializeOptions {
|
|
470
470
|
raw?: boolean;
|
|
471
471
|
documentsReturnedIn?: string | null;
|
|
472
|
+
// For now we use this internally to only prevent writeErrors from crashing the driver
|
|
473
|
+
validation?: { utf8: { writeErrors: boolean } };
|
|
472
474
|
}
|
|
473
475
|
|
|
474
476
|
/** @internal */
|
|
@@ -837,22 +839,24 @@ export class BinMsg {
|
|
|
837
839
|
const promoteValues = options.promoteValues ?? this.opts.promoteValues;
|
|
838
840
|
const promoteBuffers = options.promoteBuffers ?? this.opts.promoteBuffers;
|
|
839
841
|
const bsonRegExp = options.bsonRegExp ?? this.opts.bsonRegExp;
|
|
842
|
+
const validation = options.validation ?? { utf8: { writeErrors: false } };
|
|
840
843
|
|
|
841
844
|
// Set up the options
|
|
842
|
-
const
|
|
845
|
+
const bsonOptions: BSONSerializeOptions = {
|
|
843
846
|
promoteLongs,
|
|
844
847
|
promoteValues,
|
|
845
848
|
promoteBuffers,
|
|
846
|
-
bsonRegExp
|
|
847
|
-
|
|
849
|
+
bsonRegExp,
|
|
850
|
+
validation
|
|
851
|
+
// Due to the strictness of the BSON libraries validation option we need this cast
|
|
852
|
+
} as BSONSerializeOptions & { validation: { utf8: { writeErrors: boolean } } };
|
|
848
853
|
|
|
849
854
|
while (this.index < this.data.length) {
|
|
850
855
|
const payloadType = this.data.readUInt8(this.index++);
|
|
851
856
|
if (payloadType === 0) {
|
|
852
857
|
const bsonSize = this.data.readUInt32LE(this.index);
|
|
853
858
|
const bin = this.data.slice(this.index, this.index + bsonSize);
|
|
854
|
-
this.documents.push(raw ? bin : BSON.deserialize(bin,
|
|
855
|
-
|
|
859
|
+
this.documents.push(raw ? bin : BSON.deserialize(bin, bsonOptions));
|
|
856
860
|
this.index += bsonSize;
|
|
857
861
|
} else if (payloadType === 1) {
|
|
858
862
|
// It was decided that no driver makes use of payload type 1
|
|
@@ -865,9 +869,8 @@ export class BinMsg {
|
|
|
865
869
|
if (this.documents.length === 1 && documentsReturnedIn != null && raw) {
|
|
866
870
|
const fieldsAsRaw: Document = {};
|
|
867
871
|
fieldsAsRaw[documentsReturnedIn] = true;
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
const doc = BSON.deserialize(this.documents[0] as Buffer, _options);
|
|
872
|
+
bsonOptions.fieldsAsRaw = fieldsAsRaw;
|
|
873
|
+
const doc = BSON.deserialize(this.documents[0] as Buffer, bsonOptions);
|
|
871
874
|
this.documents = [doc];
|
|
872
875
|
}
|
|
873
876
|
|
package/src/cmap/connection.ts
CHANGED
|
@@ -55,8 +55,8 @@ export class StreamDescription {
|
|
|
55
55
|
|
|
56
56
|
receiveResponse(response: Document): void {
|
|
57
57
|
this.type = parseServerType(response);
|
|
58
|
-
|
|
59
|
-
if (
|
|
58
|
+
for (const field of RESPONSE_FIELDS) {
|
|
59
|
+
if (response[field] != null) {
|
|
60
60
|
this[field] = response[field];
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ export class StreamDescription {
|
|
|
64
64
|
if ('__nodejs_mock_server__' in response) {
|
|
65
65
|
this.__nodejs_mock_server__ = response['__nodejs_mock_server__'];
|
|
66
66
|
}
|
|
67
|
-
}
|
|
67
|
+
}
|
|
68
68
|
|
|
69
69
|
if (response.compression) {
|
|
70
70
|
this.compressor = this.compressors.filter(c => response.compression?.includes(c))[0];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const MIN_SUPPORTED_SERVER_VERSION = '
|
|
2
|
-
export const MAX_SUPPORTED_SERVER_VERSION = '5.
|
|
3
|
-
export const MIN_SUPPORTED_WIRE_VERSION =
|
|
4
|
-
export const MAX_SUPPORTED_WIRE_VERSION =
|
|
1
|
+
export const MIN_SUPPORTED_SERVER_VERSION = '3.6';
|
|
2
|
+
export const MAX_SUPPORTED_SERVER_VERSION = '5.1';
|
|
3
|
+
export const MIN_SUPPORTED_WIRE_VERSION = 6;
|
|
4
|
+
export const MAX_SUPPORTED_WIRE_VERSION = 14;
|
|
5
5
|
export const OP_REPLY = 1;
|
|
6
6
|
export const OP_UPDATE = 2001;
|
|
7
7
|
export const OP_INSERT = 2002;
|
package/src/collection.ts
CHANGED
|
@@ -93,6 +93,7 @@ import type {
|
|
|
93
93
|
TODO_NODE_3286,
|
|
94
94
|
UpdateFilter,
|
|
95
95
|
WithId,
|
|
96
|
+
WithoutId,
|
|
96
97
|
OptionalId,
|
|
97
98
|
Flatten
|
|
98
99
|
} from './mongo_types';
|
|
@@ -459,26 +460,29 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
459
460
|
* @param options - Optional settings for the command
|
|
460
461
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
461
462
|
*/
|
|
462
|
-
replaceOne(filter: Filter<TSchema>, replacement: TSchema): Promise<UpdateResult | Document>;
|
|
463
463
|
replaceOne(
|
|
464
464
|
filter: Filter<TSchema>,
|
|
465
|
-
replacement: TSchema
|
|
465
|
+
replacement: WithoutId<TSchema>
|
|
466
|
+
): Promise<UpdateResult | Document>;
|
|
467
|
+
replaceOne(
|
|
468
|
+
filter: Filter<TSchema>,
|
|
469
|
+
replacement: WithoutId<TSchema>,
|
|
466
470
|
callback: Callback<UpdateResult | Document>
|
|
467
471
|
): void;
|
|
468
472
|
replaceOne(
|
|
469
473
|
filter: Filter<TSchema>,
|
|
470
|
-
replacement: TSchema
|
|
474
|
+
replacement: WithoutId<TSchema>,
|
|
471
475
|
options: ReplaceOptions
|
|
472
476
|
): Promise<UpdateResult | Document>;
|
|
473
477
|
replaceOne(
|
|
474
478
|
filter: Filter<TSchema>,
|
|
475
|
-
replacement: TSchema
|
|
479
|
+
replacement: WithoutId<TSchema>,
|
|
476
480
|
options: ReplaceOptions,
|
|
477
481
|
callback: Callback<UpdateResult | Document>
|
|
478
482
|
): void;
|
|
479
483
|
replaceOne(
|
|
480
484
|
filter: Filter<TSchema>,
|
|
481
|
-
replacement: TSchema
|
|
485
|
+
replacement: WithoutId<TSchema>,
|
|
482
486
|
options?: ReplaceOptions | Callback<UpdateResult | Document>,
|
|
483
487
|
callback?: Callback<UpdateResult | Document>
|
|
484
488
|
): Promise<UpdateResult | Document> | void {
|
|
@@ -676,12 +680,16 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
676
680
|
* @param options - Optional settings for the command
|
|
677
681
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
678
682
|
*/
|
|
679
|
-
findOne(): Promise<TSchema | null>;
|
|
680
|
-
findOne(callback: Callback<TSchema | null>): void;
|
|
681
|
-
findOne(filter: Filter<TSchema>): Promise<TSchema | null>;
|
|
682
|
-
findOne(filter: Filter<TSchema>, callback: Callback<TSchema | null>): void;
|
|
683
|
-
findOne(filter: Filter<TSchema>, options: FindOptions): Promise<TSchema | null>;
|
|
684
|
-
findOne(
|
|
683
|
+
findOne(): Promise<WithId<TSchema> | null>;
|
|
684
|
+
findOne(callback: Callback<WithId<TSchema> | null>): void;
|
|
685
|
+
findOne(filter: Filter<TSchema>): Promise<WithId<TSchema> | null>;
|
|
686
|
+
findOne(filter: Filter<TSchema>, callback: Callback<WithId<TSchema> | null>): void;
|
|
687
|
+
findOne(filter: Filter<TSchema>, options: FindOptions): Promise<WithId<TSchema> | null>;
|
|
688
|
+
findOne(
|
|
689
|
+
filter: Filter<TSchema>,
|
|
690
|
+
options: FindOptions,
|
|
691
|
+
callback: Callback<WithId<TSchema> | null>
|
|
692
|
+
): void;
|
|
685
693
|
|
|
686
694
|
// allow an override of the schema.
|
|
687
695
|
findOne<T = TSchema>(): Promise<T | null>;
|
|
@@ -695,10 +703,10 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
695
703
|
): void;
|
|
696
704
|
|
|
697
705
|
findOne(
|
|
698
|
-
filter?: Filter<TSchema> | Callback<TSchema | null>,
|
|
699
|
-
options?: FindOptions | Callback<TSchema | null>,
|
|
700
|
-
callback?: Callback<TSchema | null>
|
|
701
|
-
): Promise<TSchema | null> | void {
|
|
706
|
+
filter?: Filter<TSchema> | Callback<WithId<TSchema> | null>,
|
|
707
|
+
options?: FindOptions | Callback<WithId<TSchema> | null>,
|
|
708
|
+
callback?: Callback<WithId<TSchema> | null>
|
|
709
|
+
): Promise<WithId<TSchema> | null> | void {
|
|
702
710
|
if (callback != null && typeof callback !== 'function') {
|
|
703
711
|
throw new MongoInvalidArgumentError(
|
|
704
712
|
'Third parameter to `findOne()` must be a callback or undefined'
|
|
@@ -706,7 +714,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
706
714
|
}
|
|
707
715
|
|
|
708
716
|
if (typeof filter === 'function') {
|
|
709
|
-
callback = filter as Callback<TSchema | null>;
|
|
717
|
+
callback = filter as Callback<WithId<TSchema> | null>;
|
|
710
718
|
filter = {};
|
|
711
719
|
options = {};
|
|
712
720
|
}
|
|
@@ -725,10 +733,10 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
725
733
|
*
|
|
726
734
|
* @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate
|
|
727
735
|
*/
|
|
728
|
-
find(): FindCursor<TSchema
|
|
729
|
-
find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema
|
|
736
|
+
find(): FindCursor<WithId<TSchema>>;
|
|
737
|
+
find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>>;
|
|
730
738
|
find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
|
|
731
|
-
find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema
|
|
739
|
+
find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<WithId<TSchema>> {
|
|
732
740
|
if (arguments.length > 2) {
|
|
733
741
|
throw new MongoInvalidArgumentError(
|
|
734
742
|
'Method "collection.find()" accepts at most two arguments'
|
|
@@ -738,7 +746,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
738
746
|
throw new MongoInvalidArgumentError('Argument "options" must not be function');
|
|
739
747
|
}
|
|
740
748
|
|
|
741
|
-
return new FindCursor<TSchema
|
|
749
|
+
return new FindCursor<WithId<TSchema>>(
|
|
742
750
|
getTopology(this),
|
|
743
751
|
this.s.namespace,
|
|
744
752
|
filter,
|
|
@@ -1275,26 +1283,29 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1275
1283
|
* @param options - Optional settings for the command
|
|
1276
1284
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
1277
1285
|
*/
|
|
1278
|
-
findOneAndReplace(filter: Filter<TSchema>, replacement: Document): Promise<ModifyResult<TSchema>>;
|
|
1279
1286
|
findOneAndReplace(
|
|
1280
1287
|
filter: Filter<TSchema>,
|
|
1281
|
-
replacement:
|
|
1288
|
+
replacement: WithoutId<TSchema>
|
|
1289
|
+
): Promise<ModifyResult<TSchema>>;
|
|
1290
|
+
findOneAndReplace(
|
|
1291
|
+
filter: Filter<TSchema>,
|
|
1292
|
+
replacement: WithoutId<TSchema>,
|
|
1282
1293
|
callback: Callback<ModifyResult<TSchema>>
|
|
1283
1294
|
): void;
|
|
1284
1295
|
findOneAndReplace(
|
|
1285
1296
|
filter: Filter<TSchema>,
|
|
1286
|
-
replacement:
|
|
1297
|
+
replacement: WithoutId<TSchema>,
|
|
1287
1298
|
options: FindOneAndReplaceOptions
|
|
1288
1299
|
): Promise<ModifyResult<TSchema>>;
|
|
1289
1300
|
findOneAndReplace(
|
|
1290
1301
|
filter: Filter<TSchema>,
|
|
1291
|
-
replacement:
|
|
1302
|
+
replacement: WithoutId<TSchema>,
|
|
1292
1303
|
options: FindOneAndReplaceOptions,
|
|
1293
1304
|
callback: Callback<ModifyResult<TSchema>>
|
|
1294
1305
|
): void;
|
|
1295
1306
|
findOneAndReplace(
|
|
1296
1307
|
filter: Filter<TSchema>,
|
|
1297
|
-
replacement:
|
|
1308
|
+
replacement: WithoutId<TSchema>,
|
|
1298
1309
|
options?: FindOneAndReplaceOptions | Callback<ModifyResult<TSchema>>,
|
|
1299
1310
|
callback?: Callback<ModifyResult<TSchema>>
|
|
1300
1311
|
): Promise<ModifyResult<TSchema>> | void {
|
|
@@ -1415,6 +1426,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1415
1426
|
/**
|
|
1416
1427
|
* Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
|
|
1417
1428
|
*
|
|
1429
|
+
* @deprecated collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.
|
|
1418
1430
|
* @param map - The mapping function.
|
|
1419
1431
|
* @param reduce - The reduce function.
|
|
1420
1432
|
* @param options - Optional settings for the command
|
|
@@ -1446,6 +1458,9 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1446
1458
|
options?: MapReduceOptions<TKey, TValue> | Callback<Document | Document[]>,
|
|
1447
1459
|
callback?: Callback<Document | Document[]>
|
|
1448
1460
|
): Promise<Document | Document[]> | void {
|
|
1461
|
+
emitWarningOnce(
|
|
1462
|
+
'collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.'
|
|
1463
|
+
);
|
|
1449
1464
|
if ('function' === typeof options) (callback = options), (options = {});
|
|
1450
1465
|
// Out must always be defined (make sure we don't break weirdly on pre 1.8+ servers)
|
|
1451
1466
|
// TODO NODE-3339: Figure out if this is still necessary given we no longer officially support pre-1.8
|