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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** @internal */
|
|
2
|
+
export class ConnectionPoolMetrics {
|
|
3
|
+
static readonly TXN = 'txn' as const;
|
|
4
|
+
static readonly CURSOR = 'cursor' as const;
|
|
5
|
+
static readonly OTHER = 'other' as const;
|
|
6
|
+
|
|
7
|
+
txnConnections = 0;
|
|
8
|
+
cursorConnections = 0;
|
|
9
|
+
otherConnections = 0;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Mark a connection as pinned for a specific operation.
|
|
13
|
+
*/
|
|
14
|
+
markPinned(pinType: string): void {
|
|
15
|
+
if (pinType === ConnectionPoolMetrics.TXN) {
|
|
16
|
+
this.txnConnections += 1;
|
|
17
|
+
} else if (pinType === ConnectionPoolMetrics.CURSOR) {
|
|
18
|
+
this.cursorConnections += 1;
|
|
19
|
+
} else {
|
|
20
|
+
this.otherConnections += 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Unmark a connection as pinned for an operation.
|
|
26
|
+
*/
|
|
27
|
+
markUnpinned(pinType: string): void {
|
|
28
|
+
if (pinType === ConnectionPoolMetrics.TXN) {
|
|
29
|
+
this.txnConnections -= 1;
|
|
30
|
+
} else if (pinType === ConnectionPoolMetrics.CURSOR) {
|
|
31
|
+
this.cursorConnections -= 1;
|
|
32
|
+
} else {
|
|
33
|
+
this.otherConnections -= 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Return information about the cmap metrics as a string.
|
|
39
|
+
*/
|
|
40
|
+
info(maxPoolSize: number): string {
|
|
41
|
+
return (
|
|
42
|
+
'Timed out while checking out a connection from connection pool: ' +
|
|
43
|
+
`maxPoolSize: ${maxPoolSize}, ` +
|
|
44
|
+
`connections in use by cursors: ${this.cursorConnections}, ` +
|
|
45
|
+
`connections in use by transactions: ${this.txnConnections}, ` +
|
|
46
|
+
`connections in use by other operations: ${this.otherConnections}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Reset the metrics to the initial values.
|
|
52
|
+
*/
|
|
53
|
+
reset(): void {
|
|
54
|
+
this.txnConnections = 0;
|
|
55
|
+
this.cursorConnections = 0;
|
|
56
|
+
this.otherConnections = 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -15,6 +15,8 @@ const RESPONSE_FIELDS = [
|
|
|
15
15
|
/** @public */
|
|
16
16
|
export interface StreamDescriptionOptions {
|
|
17
17
|
compressors?: CompressorName[];
|
|
18
|
+
logicalSessionTimeoutMinutes?: number;
|
|
19
|
+
loadBalanced: boolean;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
/** @public */
|
|
@@ -29,6 +31,7 @@ export class StreamDescription {
|
|
|
29
31
|
compressors: CompressorName[];
|
|
30
32
|
compressor?: CompressorName;
|
|
31
33
|
logicalSessionTimeoutMinutes?: number;
|
|
34
|
+
loadBalanced: boolean;
|
|
32
35
|
|
|
33
36
|
__nodejs_mock_server__?: boolean;
|
|
34
37
|
|
|
@@ -42,6 +45,8 @@ export class StreamDescription {
|
|
|
42
45
|
this.maxBsonObjectSize = 16777216;
|
|
43
46
|
this.maxMessageSizeBytes = 48000000;
|
|
44
47
|
this.maxWriteBatchSize = 100000;
|
|
48
|
+
this.logicalSessionTimeoutMinutes = options?.logicalSessionTimeoutMinutes;
|
|
49
|
+
this.loadBalanced = !!options?.loadBalanced;
|
|
45
50
|
this.compressors =
|
|
46
51
|
options && options.compressors && Array.isArray(options.compressors)
|
|
47
52
|
? options.compressors
|
|
@@ -51,7 +56,7 @@ export class StreamDescription {
|
|
|
51
56
|
receiveResponse(response: Document): void {
|
|
52
57
|
this.type = parseServerType(response);
|
|
53
58
|
RESPONSE_FIELDS.forEach(field => {
|
|
54
|
-
if (typeof response[field]
|
|
59
|
+
if (typeof response[field] != null) {
|
|
55
60
|
this[field] = response[field];
|
|
56
61
|
}
|
|
57
62
|
|
|
@@ -2,8 +2,8 @@ import * as zlib from 'zlib';
|
|
|
2
2
|
import type { Callback } from '../../utils';
|
|
3
3
|
import type { OperationDescription } from '../message_stream';
|
|
4
4
|
|
|
5
|
-
import { Snappy } from '../../deps';
|
|
6
|
-
import {
|
|
5
|
+
import { PKG_VERSION, Snappy } from '../../deps';
|
|
6
|
+
import { MongoDecompressionError, MongoInvalidArgumentError } from '../../error';
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
9
|
export const Compressor = Object.freeze({
|
|
@@ -39,12 +39,20 @@ export function compress(
|
|
|
39
39
|
): void {
|
|
40
40
|
const zlibOptions = {} as zlib.ZlibOptions;
|
|
41
41
|
switch (self.options.agreedCompressor) {
|
|
42
|
-
case 'snappy':
|
|
42
|
+
case 'snappy': {
|
|
43
43
|
if ('kModuleError' in Snappy) {
|
|
44
44
|
return callback(Snappy['kModuleError']);
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
|
|
47
|
+
if (Snappy[PKG_VERSION].major <= 6) {
|
|
48
|
+
Snappy.compress(dataToBeCompressed, callback);
|
|
49
|
+
} else {
|
|
50
|
+
Snappy.compress(dataToBeCompressed)
|
|
51
|
+
.then(buffer => callback(undefined, buffer))
|
|
52
|
+
.catch(error => callback(error));
|
|
53
|
+
}
|
|
47
54
|
break;
|
|
55
|
+
}
|
|
48
56
|
case 'zlib':
|
|
49
57
|
// Determine zlibCompressionLevel
|
|
50
58
|
if (self.options.zlibCompressionLevel) {
|
|
@@ -53,10 +61,8 @@ export function compress(
|
|
|
53
61
|
zlib.deflate(dataToBeCompressed, zlibOptions, callback as zlib.CompressCallback);
|
|
54
62
|
break;
|
|
55
63
|
default:
|
|
56
|
-
throw new
|
|
57
|
-
|
|
58
|
-
self.options.agreedCompressor +
|
|
59
|
-
'".'
|
|
64
|
+
throw new MongoInvalidArgumentError(
|
|
65
|
+
`Unknown compressor ${self.options.agreedCompressor} failed to compress`
|
|
60
66
|
);
|
|
61
67
|
}
|
|
62
68
|
}
|
|
@@ -68,19 +74,26 @@ export function decompress(
|
|
|
68
74
|
callback: Callback<Buffer>
|
|
69
75
|
): void {
|
|
70
76
|
if (compressorID < 0 || compressorID > Math.max(2)) {
|
|
71
|
-
throw new
|
|
72
|
-
`Server sent message compressed using an unsupported compressor
|
|
73
|
-
` (Received compressor ID ${compressorID})`
|
|
77
|
+
throw new MongoDecompressionError(
|
|
78
|
+
`Server sent message compressed using an unsupported compressor. (Received compressor ID ${compressorID})`
|
|
74
79
|
);
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
switch (compressorID) {
|
|
78
|
-
case Compressor.snappy:
|
|
83
|
+
case Compressor.snappy: {
|
|
79
84
|
if ('kModuleError' in Snappy) {
|
|
80
85
|
return callback(Snappy['kModuleError']);
|
|
81
86
|
}
|
|
82
|
-
|
|
87
|
+
|
|
88
|
+
if (Snappy[PKG_VERSION].major <= 6) {
|
|
89
|
+
Snappy.uncompress(compressedData, { asBuffer: true }, callback);
|
|
90
|
+
} else {
|
|
91
|
+
Snappy.uncompress(compressedData, { asBuffer: true })
|
|
92
|
+
.then(buffer => callback(undefined, buffer))
|
|
93
|
+
.catch(error => callback(error));
|
|
94
|
+
}
|
|
83
95
|
break;
|
|
96
|
+
}
|
|
84
97
|
case Compressor.zlib:
|
|
85
98
|
zlib.inflate(compressedData, callback as zlib.CompressCallback);
|
|
86
99
|
break;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ServerType } from '../../sdam/common';
|
|
2
2
|
import { TopologyDescription } from '../../sdam/topology_description';
|
|
3
|
-
import {
|
|
3
|
+
import { MongoInvalidArgumentError } from '../../error';
|
|
4
4
|
import { ReadPreference } from '../../read_preference';
|
|
5
5
|
import type { Document } from '../../bson';
|
|
6
6
|
import type { OpQueryOptions } from '../commands';
|
|
@@ -28,7 +28,9 @@ export function getReadPreference(cmd: Document, options?: ReadPreferenceOption)
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (!(readPreference instanceof ReadPreference)) {
|
|
31
|
-
throw new
|
|
31
|
+
throw new MongoInvalidArgumentError(
|
|
32
|
+
'Option "readPreference" must be a ReadPreference instance'
|
|
33
|
+
);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
return readPreference;
|
package/src/collection.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
getTopology
|
|
9
9
|
} from './utils';
|
|
10
10
|
import { Document, BSONSerializeOptions, resolveBSONOptions } from './bson';
|
|
11
|
-
import {
|
|
11
|
+
import { MongoInvalidArgumentError } from './error';
|
|
12
12
|
import { UnorderedBulkOperation } from './bulk/unordered';
|
|
13
13
|
import { OrderedBulkOperation } from './bulk/ordered';
|
|
14
14
|
import { ChangeStream, ChangeStreamOptions } from './change_stream';
|
|
@@ -40,7 +40,6 @@ import {
|
|
|
40
40
|
EstimatedDocumentCountOptions
|
|
41
41
|
} from './operations/estimated_document_count';
|
|
42
42
|
import type { FindOptions } from './operations/find';
|
|
43
|
-
import { FindOneOperation } from './operations/find_one';
|
|
44
43
|
import {
|
|
45
44
|
FindOneAndDeleteOperation,
|
|
46
45
|
FindOneAndReplaceOperation,
|
|
@@ -100,7 +99,7 @@ import type {
|
|
|
100
99
|
|
|
101
100
|
/** @public */
|
|
102
101
|
export interface ModifyResult<TSchema = Document> {
|
|
103
|
-
value
|
|
102
|
+
value: TSchema | null;
|
|
104
103
|
lastErrorObject?: Document;
|
|
105
104
|
ok: 0 | 1;
|
|
106
105
|
}
|
|
@@ -390,7 +389,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
390
389
|
options = options || { ordered: true };
|
|
391
390
|
|
|
392
391
|
if (!Array.isArray(operations)) {
|
|
393
|
-
throw new
|
|
392
|
+
throw new MongoInvalidArgumentError('Argument "operations" must be an array of documents');
|
|
394
393
|
}
|
|
395
394
|
|
|
396
395
|
return executeOperation(
|
|
@@ -415,34 +414,39 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
415
414
|
updateOne(
|
|
416
415
|
filter: Filter<TSchema>,
|
|
417
416
|
update: UpdateFilter<TSchema> | Partial<TSchema>
|
|
418
|
-
): Promise<UpdateResult
|
|
417
|
+
): Promise<UpdateResult>;
|
|
419
418
|
updateOne(
|
|
420
419
|
filter: Filter<TSchema>,
|
|
421
420
|
update: UpdateFilter<TSchema> | Partial<TSchema>,
|
|
422
|
-
callback: Callback<UpdateResult
|
|
421
|
+
callback: Callback<UpdateResult>
|
|
423
422
|
): void;
|
|
424
423
|
updateOne(
|
|
425
424
|
filter: Filter<TSchema>,
|
|
426
425
|
update: UpdateFilter<TSchema> | Partial<TSchema>,
|
|
427
426
|
options: UpdateOptions
|
|
428
|
-
): Promise<UpdateResult
|
|
427
|
+
): Promise<UpdateResult>;
|
|
429
428
|
updateOne(
|
|
430
429
|
filter: Filter<TSchema>,
|
|
431
430
|
update: UpdateFilter<TSchema> | Partial<TSchema>,
|
|
432
431
|
options: UpdateOptions,
|
|
433
|
-
callback: Callback<UpdateResult
|
|
432
|
+
callback: Callback<UpdateResult>
|
|
434
433
|
): void;
|
|
435
434
|
updateOne(
|
|
436
435
|
filter: Filter<TSchema>,
|
|
437
436
|
update: UpdateFilter<TSchema> | Partial<TSchema>,
|
|
438
|
-
options?: UpdateOptions | Callback<UpdateResult
|
|
439
|
-
callback?: Callback<UpdateResult
|
|
440
|
-
): Promise<UpdateResult
|
|
437
|
+
options?: UpdateOptions | Callback<UpdateResult>,
|
|
438
|
+
callback?: Callback<UpdateResult>
|
|
439
|
+
): Promise<UpdateResult> | void {
|
|
441
440
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
442
441
|
|
|
443
442
|
return executeOperation(
|
|
444
443
|
getTopology(this),
|
|
445
|
-
new UpdateOneOperation(
|
|
444
|
+
new UpdateOneOperation(
|
|
445
|
+
this as TODO_NODE_3286,
|
|
446
|
+
filter,
|
|
447
|
+
update,
|
|
448
|
+
resolveOptions(this, options)
|
|
449
|
+
) as TODO_NODE_3286,
|
|
446
450
|
callback
|
|
447
451
|
);
|
|
448
452
|
}
|
|
@@ -621,7 +625,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
621
625
|
*/
|
|
622
626
|
rename(newName: string): Promise<Collection>;
|
|
623
627
|
rename(newName: string, callback: Callback<Collection>): void;
|
|
624
|
-
rename(newName: string, options: RenameOptions): Promise<Collection
|
|
628
|
+
rename(newName: string, options: RenameOptions): Promise<Collection>;
|
|
625
629
|
rename(newName: string, options: RenameOptions, callback: Callback<Collection>): void;
|
|
626
630
|
rename(
|
|
627
631
|
newName: string,
|
|
@@ -672,52 +676,48 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
672
676
|
* @param options - Optional settings for the command
|
|
673
677
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
674
678
|
*/
|
|
675
|
-
findOne(): Promise<TSchema |
|
|
676
|
-
findOne(callback: Callback<TSchema |
|
|
677
|
-
findOne(filter: Filter<TSchema>): Promise<TSchema |
|
|
678
|
-
findOne(filter: Filter<TSchema>, callback: Callback<TSchema |
|
|
679
|
-
findOne(filter: Filter<TSchema>, options: FindOptions
|
|
680
|
-
findOne(
|
|
681
|
-
filter: Filter<TSchema>,
|
|
682
|
-
options: FindOptions<TSchema>,
|
|
683
|
-
callback: Callback<TSchema | undefined>
|
|
684
|
-
): void;
|
|
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(filter: Filter<TSchema>, options: FindOptions, callback: Callback<TSchema | null>): void;
|
|
685
685
|
|
|
686
686
|
// allow an override of the schema.
|
|
687
|
-
findOne<T = TSchema>(): Promise<T |
|
|
688
|
-
findOne<T = TSchema>(callback: Callback<T |
|
|
689
|
-
findOne<T = TSchema>(filter: Filter<
|
|
690
|
-
findOne<T = TSchema>(filter: Filter<
|
|
687
|
+
findOne<T = TSchema>(): Promise<T | null>;
|
|
688
|
+
findOne<T = TSchema>(callback: Callback<T | null>): void;
|
|
689
|
+
findOne<T = TSchema>(filter: Filter<TSchema>): Promise<T | null>;
|
|
690
|
+
findOne<T = TSchema>(filter: Filter<TSchema>, options?: FindOptions): Promise<T | null>;
|
|
691
691
|
findOne<T = TSchema>(
|
|
692
|
-
filter: Filter<
|
|
693
|
-
options?: FindOptions
|
|
694
|
-
callback?: Callback<T |
|
|
692
|
+
filter: Filter<TSchema>,
|
|
693
|
+
options?: FindOptions,
|
|
694
|
+
callback?: Callback<T | null>
|
|
695
695
|
): void;
|
|
696
696
|
|
|
697
697
|
findOne(
|
|
698
|
-
filter?: Filter<TSchema> | Callback<TSchema |
|
|
699
|
-
options?: FindOptions
|
|
700
|
-
callback?: Callback<TSchema>
|
|
701
|
-
): Promise<TSchema |
|
|
702
|
-
if (callback
|
|
703
|
-
throw new
|
|
698
|
+
filter?: Filter<TSchema> | Callback<TSchema | null>,
|
|
699
|
+
options?: FindOptions | Callback<TSchema | null>,
|
|
700
|
+
callback?: Callback<TSchema | null>
|
|
701
|
+
): Promise<TSchema | null> | void {
|
|
702
|
+
if (callback != null && typeof callback !== 'function') {
|
|
703
|
+
throw new MongoInvalidArgumentError(
|
|
704
|
+
'Third parameter to `findOne()` must be a callback or undefined'
|
|
705
|
+
);
|
|
704
706
|
}
|
|
705
707
|
|
|
706
|
-
if (typeof filter === 'function')
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
708
|
+
if (typeof filter === 'function') {
|
|
709
|
+
callback = filter as Callback<TSchema | null>;
|
|
710
|
+
filter = {};
|
|
711
|
+
options = {};
|
|
712
|
+
}
|
|
713
|
+
if (typeof options === 'function') {
|
|
714
|
+
callback = options;
|
|
715
|
+
options = {};
|
|
716
|
+
}
|
|
711
717
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
this as TODO_NODE_3286,
|
|
716
|
-
filter,
|
|
717
|
-
resolveOptions(this, options)
|
|
718
|
-
) as TODO_NODE_3286,
|
|
719
|
-
callback as TODO_NODE_3286
|
|
720
|
-
);
|
|
718
|
+
const finalFilter = filter ?? {};
|
|
719
|
+
const finalOptions = options ?? {};
|
|
720
|
+
return this.find(finalFilter, finalOptions).limit(-1).batchSize(1).next(callback);
|
|
721
721
|
}
|
|
722
722
|
|
|
723
723
|
/**
|
|
@@ -726,14 +726,16 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
726
726
|
* @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate
|
|
727
727
|
*/
|
|
728
728
|
find(): FindCursor<TSchema>;
|
|
729
|
-
find(filter: Filter<TSchema>, options?: FindOptions
|
|
730
|
-
find<T
|
|
731
|
-
find(filter?: Filter<TSchema>, options?: FindOptions
|
|
729
|
+
find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema>;
|
|
730
|
+
find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
|
|
731
|
+
find(filter?: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema> {
|
|
732
732
|
if (arguments.length > 2) {
|
|
733
|
-
throw new
|
|
733
|
+
throw new MongoInvalidArgumentError(
|
|
734
|
+
'Method "collection.find()" accepts at most two arguments'
|
|
735
|
+
);
|
|
734
736
|
}
|
|
735
737
|
if (typeof options === 'function') {
|
|
736
|
-
throw new
|
|
738
|
+
throw new MongoInvalidArgumentError('Argument "options" must not be function');
|
|
737
739
|
}
|
|
738
740
|
|
|
739
741
|
return new FindCursor<TSchema>(
|
|
@@ -1084,7 +1086,7 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1084
1086
|
options?: CountDocumentsOptions | Callback<number>,
|
|
1085
1087
|
callback?: Callback<number>
|
|
1086
1088
|
): Promise<number> | void {
|
|
1087
|
-
if (
|
|
1089
|
+
if (filter == null) {
|
|
1088
1090
|
(filter = {}), (options = {}), (callback = undefined);
|
|
1089
1091
|
} else if (typeof filter === 'function') {
|
|
1090
1092
|
(callback = filter as Callback<number>), (filter = {}), (options = {});
|
|
@@ -1188,14 +1190,14 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1188
1190
|
* @param options - Optional settings for the command
|
|
1189
1191
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
1190
1192
|
*/
|
|
1191
|
-
indexes(): Promise<Document>;
|
|
1192
|
-
indexes(callback: Callback<Document>): void;
|
|
1193
|
-
indexes(options: IndexInformationOptions): Promise<Document>;
|
|
1194
|
-
indexes(options: IndexInformationOptions, callback: Callback<Document>): void;
|
|
1193
|
+
indexes(): Promise<Document[]>;
|
|
1194
|
+
indexes(callback: Callback<Document[]>): void;
|
|
1195
|
+
indexes(options: IndexInformationOptions): Promise<Document[]>;
|
|
1196
|
+
indexes(options: IndexInformationOptions, callback: Callback<Document[]>): void;
|
|
1195
1197
|
indexes(
|
|
1196
|
-
options?: IndexInformationOptions | Callback<Document>,
|
|
1197
|
-
callback?: Callback<Document>
|
|
1198
|
-
): Promise<Document> | void {
|
|
1198
|
+
options?: IndexInformationOptions | Callback<Document[]>,
|
|
1199
|
+
callback?: Callback<Document[]>
|
|
1200
|
+
): Promise<Document[]> | void {
|
|
1199
1201
|
if (typeof options === 'function') (callback = options), (options = {});
|
|
1200
1202
|
|
|
1201
1203
|
return executeOperation(
|
|
@@ -1237,11 +1239,11 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1237
1239
|
* @param callback - An optional callback, a Promise will be returned if none is provided
|
|
1238
1240
|
*/
|
|
1239
1241
|
findOneAndDelete(filter: Filter<TSchema>): Promise<ModifyResult<TSchema>>;
|
|
1240
|
-
findOneAndDelete(filter: Filter<TSchema>, callback: Callback<ModifyResult<TSchema>>): void;
|
|
1241
1242
|
findOneAndDelete(
|
|
1242
1243
|
filter: Filter<TSchema>,
|
|
1243
1244
|
options: FindOneAndDeleteOptions
|
|
1244
1245
|
): Promise<ModifyResult<TSchema>>;
|
|
1246
|
+
findOneAndDelete(filter: Filter<TSchema>, callback: Callback<ModifyResult<TSchema>>): void;
|
|
1245
1247
|
findOneAndDelete(
|
|
1246
1248
|
filter: Filter<TSchema>,
|
|
1247
1249
|
options: FindOneAndDeleteOptions,
|
|
@@ -1369,17 +1371,20 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1369
1371
|
options?: AggregateOptions
|
|
1370
1372
|
): AggregationCursor<T> {
|
|
1371
1373
|
if (arguments.length > 2) {
|
|
1372
|
-
throw new
|
|
1374
|
+
throw new MongoInvalidArgumentError(
|
|
1375
|
+
'Method "collection.aggregate()" accepts at most two arguments'
|
|
1376
|
+
);
|
|
1373
1377
|
}
|
|
1374
1378
|
if (!Array.isArray(pipeline)) {
|
|
1375
|
-
throw new
|
|
1379
|
+
throw new MongoInvalidArgumentError(
|
|
1380
|
+
'Argument "pipeline" must be an array of aggregation stages'
|
|
1381
|
+
);
|
|
1376
1382
|
}
|
|
1377
1383
|
if (typeof options === 'function') {
|
|
1378
|
-
throw new
|
|
1384
|
+
throw new MongoInvalidArgumentError('Argument "options" must not be function');
|
|
1379
1385
|
}
|
|
1380
1386
|
|
|
1381
1387
|
return new AggregationCursor(
|
|
1382
|
-
this as TODO_NODE_3286,
|
|
1383
1388
|
getTopology(this),
|
|
1384
1389
|
this.s.namespace,
|
|
1385
1390
|
pipeline,
|
|
@@ -1445,8 +1450,8 @@ export class Collection<TSchema extends Document = Document> {
|
|
|
1445
1450
|
// Out must always be defined (make sure we don't break weirdly on pre 1.8+ servers)
|
|
1446
1451
|
// TODO NODE-3339: Figure out if this is still necessary given we no longer officially support pre-1.8
|
|
1447
1452
|
if (options?.out == null) {
|
|
1448
|
-
throw new
|
|
1449
|
-
'
|
|
1453
|
+
throw new MongoInvalidArgumentError(
|
|
1454
|
+
'Option "out" must be defined, see mongodb docs for possible values'
|
|
1450
1455
|
);
|
|
1451
1456
|
}
|
|
1452
1457
|
|