mongodb 4.3.1 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/lib/admin.js +5 -6
- package/lib/admin.js.map +1 -1
- package/lib/bulk/common.js +31 -7
- package/lib/bulk/common.js.map +1 -1
- package/lib/bulk/unordered.js.map +1 -1
- package/lib/change_stream.js +29 -20
- package/lib/change_stream.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +49 -7
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +12 -1
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/scram.js +1 -0
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +0 -6
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +111 -86
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/errors.js.map +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/stream_description.js +3 -0
- package/lib/cmap/stream_description.js.map +1 -1
- package/lib/collection.js +29 -28
- package/lib/collection.js.map +1 -1
- package/lib/connection_string.js +53 -40
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +64 -42
- package/lib/cursor/abstract_cursor.js.map +1 -1
- package/lib/cursor/aggregation_cursor.js +2 -2
- package/lib/cursor/aggregation_cursor.js.map +1 -1
- package/lib/cursor/find_cursor.js +4 -3
- package/lib/cursor/find_cursor.js.map +1 -1
- package/lib/db.js +13 -13
- package/lib/db.js.map +1 -1
- package/lib/encrypter.js +17 -9
- package/lib/encrypter.js.map +1 -1
- package/lib/error.js +99 -48
- package/lib/error.js.map +1 -1
- package/lib/gridfs/download.js +2 -0
- package/lib/gridfs/download.js.map +1 -1
- package/lib/gridfs/index.js +42 -51
- package/lib/gridfs/index.js.map +1 -1
- package/lib/gridfs/upload.js.map +1 -1
- package/lib/index.js +9 -2
- package/lib/index.js.map +1 -1
- package/lib/mongo_client.js +14 -27
- package/lib/mongo_client.js.map +1 -1
- package/lib/operations/add_user.js +8 -1
- package/lib/operations/add_user.js.map +1 -1
- package/lib/operations/aggregate.js +5 -0
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/bulk_write.js.map +1 -1
- package/lib/operations/collections.js.map +1 -1
- package/lib/operations/command.js.map +1 -1
- package/lib/operations/common_functions.js +8 -1
- package/lib/operations/common_functions.js.map +1 -1
- package/lib/operations/count.js.map +1 -1
- package/lib/operations/count_documents.js.map +1 -1
- package/lib/operations/create_collection.js.map +1 -1
- package/lib/operations/delete.js +5 -3
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js.map +1 -1
- package/lib/operations/drop.js.map +1 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/eval.js.map +1 -1
- package/lib/operations/execute_operation.js +70 -79
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +3 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +5 -0
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +5 -0
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +8 -9
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +3 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/is_capped.js.map +1 -1
- package/lib/operations/list_collections.js +10 -42
- package/lib/operations/list_collections.js.map +1 -1
- package/lib/operations/list_databases.js +5 -0
- package/lib/operations/list_databases.js.map +1 -1
- package/lib/operations/map_reduce.js +1 -2
- package/lib/operations/map_reduce.js.map +1 -1
- package/lib/operations/operation.js +1 -3
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/options_operation.js.map +1 -1
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js.map +1 -1
- package/lib/operations/rename.js +1 -1
- package/lib/operations/rename.js.map +1 -1
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +5 -0
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/read_concern.js +1 -0
- package/lib/read_concern.js.map +1 -1
- package/lib/sdam/common.js +1 -7
- package/lib/sdam/common.js.map +1 -1
- package/lib/sdam/events.js +1 -1
- package/lib/sdam/events.js.map +1 -1
- package/lib/sdam/monitor.js +1 -2
- package/lib/sdam/monitor.js.map +1 -1
- package/lib/sdam/server.js +79 -57
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +16 -33
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sdam/topology_description.js +1 -3
- package/lib/sdam/topology_description.js.map +1 -1
- package/lib/sessions.js +93 -68
- package/lib/sessions.js.map +1 -1
- package/lib/utils.js +21 -97
- package/lib/utils.js.map +1 -1
- package/mongodb.d.ts +188 -29
- package/package.json +46 -46
- package/src/admin.ts +6 -10
- package/src/bulk/common.ts +42 -14
- package/src/bulk/unordered.ts +1 -1
- package/src/change_stream.ts +58 -42
- package/src/cmap/auth/gssapi.ts +58 -7
- package/src/cmap/auth/mongo_credentials.ts +17 -2
- package/src/cmap/auth/mongocr.ts +1 -1
- package/src/cmap/auth/mongodb_aws.ts +1 -1
- package/src/cmap/auth/plain.ts +1 -1
- package/src/cmap/auth/scram.ts +3 -2
- package/src/cmap/auth/x509.ts +6 -2
- package/src/cmap/commands.ts +3 -0
- package/src/cmap/connect.ts +2 -20
- package/src/cmap/connection.ts +162 -111
- package/src/cmap/errors.ts +2 -2
- package/src/cmap/message_stream.ts +2 -2
- package/src/cmap/stream_description.ts +4 -1
- package/src/collection.ts +37 -33
- package/src/connection_string.ts +77 -45
- package/src/cursor/abstract_cursor.ts +85 -56
- package/src/cursor/aggregation_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +19 -11
- package/src/db.ts +15 -19
- package/src/deps.ts +52 -0
- package/src/encrypter.ts +18 -10
- package/src/error.ts +145 -76
- package/src/gridfs/download.ts +3 -1
- package/src/gridfs/index.ts +51 -68
- package/src/gridfs/upload.ts +12 -12
- package/src/index.ts +10 -1
- package/src/mongo_client.ts +19 -41
- package/src/operations/add_user.ts +14 -3
- package/src/operations/aggregate.ts +15 -5
- package/src/operations/bulk_write.ts +6 -2
- package/src/operations/collections.ts +6 -2
- package/src/operations/command.ts +23 -8
- package/src/operations/common_functions.ts +8 -1
- package/src/operations/count.ts +6 -2
- package/src/operations/count_documents.ts +5 -1
- package/src/operations/create_collection.ts +6 -2
- package/src/operations/delete.ts +19 -13
- package/src/operations/distinct.ts +6 -2
- package/src/operations/drop.ts +12 -4
- package/src/operations/estimated_document_count.ts +11 -3
- package/src/operations/eval.ts +6 -2
- package/src/operations/execute_operation.ts +102 -101
- package/src/operations/find.ts +9 -5
- package/src/operations/find_and_modify.ts +21 -2
- package/src/operations/get_more.ts +20 -6
- package/src/operations/indexes.ts +54 -36
- package/src/operations/insert.ts +20 -6
- package/src/operations/is_capped.ts +6 -2
- package/src/operations/list_collections.ts +24 -59
- package/src/operations/list_databases.ts +13 -3
- package/src/operations/map_reduce.ts +7 -6
- package/src/operations/operation.ts +10 -9
- package/src/operations/options_operation.ts +6 -2
- package/src/operations/profiling_level.ts +6 -2
- package/src/operations/remove_user.ts +6 -2
- package/src/operations/rename.ts +7 -3
- package/src/operations/run_command.ts +6 -2
- package/src/operations/set_profiling_level.ts +6 -2
- package/src/operations/stats.ts +12 -4
- package/src/operations/update.ts +21 -9
- package/src/operations/validate_collection.ts +6 -2
- package/src/read_concern.ts +1 -0
- package/src/sdam/common.ts +0 -6
- package/src/sdam/events.ts +2 -2
- package/src/sdam/monitor.ts +4 -5
- package/src/sdam/server.ts +95 -90
- package/src/sdam/topology.ts +9 -53
- package/src/sdam/topology_description.ts +1 -3
- package/src/sessions.ts +108 -78
- package/src/utils.ts +38 -118
- package/tsconfig.json +40 -0
- package/mongodb.ts34.d.ts +0 -5649
package/src/gridfs/upload.ts
CHANGED
|
@@ -119,15 +119,15 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
|
|
|
119
119
|
* @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
|
|
120
120
|
* @returns False if this write required flushing a chunk to MongoDB. True otherwise.
|
|
121
121
|
*/
|
|
122
|
-
write(chunk: Buffer | string): boolean;
|
|
123
|
-
write(chunk: Buffer | string, callback: Callback<void>): boolean;
|
|
124
|
-
write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
|
|
125
|
-
write(
|
|
122
|
+
override write(chunk: Buffer | string): boolean;
|
|
123
|
+
override write(chunk: Buffer | string, callback: Callback<void>): boolean;
|
|
124
|
+
override write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
|
|
125
|
+
override write(
|
|
126
126
|
chunk: Buffer | string,
|
|
127
127
|
encoding: BufferEncoding | undefined,
|
|
128
128
|
callback: Callback<void>
|
|
129
129
|
): boolean;
|
|
130
|
-
write(
|
|
130
|
+
override write(
|
|
131
131
|
chunk: Buffer | string,
|
|
132
132
|
encodingOrCallback?: Callback<void> | BufferEncoding,
|
|
133
133
|
callback?: Callback<void>
|
|
@@ -172,17 +172,17 @@ export class GridFSBucketWriteStream extends Writable implements NodeJS.Writable
|
|
|
172
172
|
* @param encoding - Optional encoding for the buffer
|
|
173
173
|
* @param callback - Function to call when all files and chunks have been persisted to MongoDB
|
|
174
174
|
*/
|
|
175
|
-
end(): this;
|
|
176
|
-
end(chunk: Buffer): this;
|
|
177
|
-
end(callback: Callback<GridFSFile | void>): this;
|
|
178
|
-
end(chunk: Buffer, callback: Callback<GridFSFile | void>): this;
|
|
179
|
-
end(chunk: Buffer, encoding: BufferEncoding): this;
|
|
180
|
-
end(
|
|
175
|
+
override end(): this;
|
|
176
|
+
override end(chunk: Buffer): this;
|
|
177
|
+
override end(callback: Callback<GridFSFile | void>): this;
|
|
178
|
+
override end(chunk: Buffer, callback: Callback<GridFSFile | void>): this;
|
|
179
|
+
override end(chunk: Buffer, encoding: BufferEncoding): this;
|
|
180
|
+
override end(
|
|
181
181
|
chunk: Buffer,
|
|
182
182
|
encoding: BufferEncoding | undefined,
|
|
183
183
|
callback: Callback<GridFSFile | void>
|
|
184
184
|
): this;
|
|
185
|
-
end(
|
|
185
|
+
override end(
|
|
186
186
|
chunkOrCallback?: Buffer | Callback<GridFSFile | void>,
|
|
187
187
|
encodingOrCallback?: BufferEncoding | Callback<GridFSFile | void>,
|
|
188
188
|
callback?: Callback<GridFSFile | void>
|
package/src/index.ts
CHANGED
|
@@ -62,8 +62,10 @@ export {
|
|
|
62
62
|
MongoServerError,
|
|
63
63
|
MongoServerSelectionError,
|
|
64
64
|
MongoSystemError,
|
|
65
|
+
MongoTailableCursorError,
|
|
65
66
|
MongoTopologyClosedError,
|
|
66
67
|
MongoTransactionError,
|
|
68
|
+
MongoUnexpectedServerResponseError,
|
|
67
69
|
MongoWriteConcernError
|
|
68
70
|
} from './error';
|
|
69
71
|
export {
|
|
@@ -86,10 +88,12 @@ export {
|
|
|
86
88
|
|
|
87
89
|
// enums
|
|
88
90
|
export { BatchType } from './bulk/common';
|
|
91
|
+
export { GSSAPICanonicalizationValue } from './cmap/auth/gssapi';
|
|
89
92
|
export { AuthMechanism } from './cmap/auth/providers';
|
|
90
93
|
export { Compressor } from './cmap/wire_protocol/compression';
|
|
91
94
|
export { CURSOR_FLAGS } from './cursor/abstract_cursor';
|
|
92
95
|
export { AutoEncryptionLoggerLevel } from './deps';
|
|
96
|
+
export { MongoErrorLabel } from './error';
|
|
93
97
|
export { ExplainVerbosity } from './explain';
|
|
94
98
|
export { LoggerLevel } from './logger';
|
|
95
99
|
export { ServerApiVersion } from './mongo_client';
|
|
@@ -182,12 +186,17 @@ export type {
|
|
|
182
186
|
MongoCredentialsOptions
|
|
183
187
|
} from './cmap/auth/mongo_credentials';
|
|
184
188
|
export type {
|
|
189
|
+
BinMsg,
|
|
185
190
|
GetMore,
|
|
186
191
|
KillCursor,
|
|
192
|
+
MessageHeader,
|
|
187
193
|
Msg,
|
|
188
194
|
OpGetMoreOptions,
|
|
195
|
+
OpMsgOptions,
|
|
189
196
|
OpQueryOptions,
|
|
197
|
+
OpResponseOptions,
|
|
190
198
|
Query,
|
|
199
|
+
Response,
|
|
191
200
|
WriteProtocolMessageType
|
|
192
201
|
} from './cmap/commands';
|
|
193
202
|
export type { LEGAL_TCP_SOCKET_OPTIONS, LEGAL_TLS_SOCKET_OPTIONS, Stream } from './cmap/connect';
|
|
@@ -229,7 +238,7 @@ export type {
|
|
|
229
238
|
export type { InternalAbstractCursorOptions } from './cursor/abstract_cursor';
|
|
230
239
|
export type { AggregationCursorOptions } from './cursor/aggregation_cursor';
|
|
231
240
|
export type { DbOptions, DbPrivate } from './db';
|
|
232
|
-
export type { AutoEncrypter, AutoEncryptionOptions } from './deps';
|
|
241
|
+
export type { AutoEncrypter, AutoEncryptionOptions, AutoEncryptionTlsOptions } from './deps';
|
|
233
242
|
export type { Encrypter, EncrypterOptions } from './encrypter';
|
|
234
243
|
export type { AnyError, ErrorDescription, MongoNetworkErrorOptions } from './error';
|
|
235
244
|
export type { Explain, ExplainOptions, ExplainVerbosityLike } from './explain';
|
package/src/mongo_client.ts
CHANGED
|
@@ -13,12 +13,7 @@ import type { MONGO_CLIENT_EVENTS } from './constants';
|
|
|
13
13
|
import { Db, DbOptions } from './db';
|
|
14
14
|
import type { AutoEncrypter, AutoEncryptionOptions } from './deps';
|
|
15
15
|
import type { Encrypter } from './encrypter';
|
|
16
|
-
import {
|
|
17
|
-
AnyError,
|
|
18
|
-
MongoInvalidArgumentError,
|
|
19
|
-
MongoNotConnectedError,
|
|
20
|
-
MongoRuntimeError
|
|
21
|
-
} from './error';
|
|
16
|
+
import { MongoInvalidArgumentError, MongoNotConnectedError } from './error';
|
|
22
17
|
import type { Logger, LoggerLevel } from './logger';
|
|
23
18
|
import { TypedEventEmitter } from './mongo_types';
|
|
24
19
|
import { connect } from './operations/connect';
|
|
@@ -75,8 +70,6 @@ export interface PkFactory {
|
|
|
75
70
|
createPk(): any; // TODO: when js-bson is typed, function should return some BSON type
|
|
76
71
|
}
|
|
77
72
|
|
|
78
|
-
type CleanUpHandlerFunction = (err?: AnyError, result?: any, opts?: any) => Promise<void>;
|
|
79
|
-
|
|
80
73
|
/** @public */
|
|
81
74
|
export type SupportedTLSConnectionOptions = Pick<
|
|
82
75
|
TLSConnectionOptions,
|
|
@@ -264,7 +257,7 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
|
|
|
264
257
|
}
|
|
265
258
|
|
|
266
259
|
/** @public */
|
|
267
|
-
export type WithSessionCallback = (session: ClientSession) => Promise<any
|
|
260
|
+
export type WithSessionCallback = (session: ClientSession) => Promise<any>;
|
|
268
261
|
|
|
269
262
|
/** @internal */
|
|
270
263
|
export interface MongoClientPrivate {
|
|
@@ -564,44 +557,29 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
564
557
|
optionsOrOperation?: ClientSessionOptions | WithSessionCallback,
|
|
565
558
|
callback?: WithSessionCallback
|
|
566
559
|
): Promise<void> {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
560
|
+
const options = {
|
|
561
|
+
// Always define an owner
|
|
562
|
+
owner: Symbol(),
|
|
563
|
+
// If it's an object inherit the options
|
|
564
|
+
...(typeof optionsOrOperation === 'object' ? optionsOrOperation : {})
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const withSessionCallback =
|
|
568
|
+
typeof optionsOrOperation === 'function' ? optionsOrOperation : callback;
|
|
572
569
|
|
|
573
|
-
if (
|
|
570
|
+
if (withSessionCallback == null) {
|
|
574
571
|
throw new MongoInvalidArgumentError('Missing required callback parameter');
|
|
575
572
|
}
|
|
576
573
|
|
|
577
574
|
const session = this.startSession(options);
|
|
578
575
|
const Promise = PromiseProvider.get();
|
|
579
576
|
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
//
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
opts = Object.assign({ throw: true }, opts);
|
|
588
|
-
session.endSession();
|
|
589
|
-
|
|
590
|
-
if (err) {
|
|
591
|
-
if (opts.throw) throw err;
|
|
592
|
-
return Promise.reject(err);
|
|
593
|
-
}
|
|
594
|
-
}) as CleanUpHandlerFunction;
|
|
595
|
-
|
|
596
|
-
try {
|
|
597
|
-
const result = callback(session);
|
|
598
|
-
return Promise.resolve(result).then(
|
|
599
|
-
result => cleanupHandler(undefined, result, undefined),
|
|
600
|
-
err => cleanupHandler(err, null, { throw: true })
|
|
601
|
-
);
|
|
602
|
-
} catch (err) {
|
|
603
|
-
return cleanupHandler(err, null, { throw: false }) as Promise<void>;
|
|
604
|
-
}
|
|
577
|
+
return Promise.resolve()
|
|
578
|
+
.then(() => withSessionCallback(session))
|
|
579
|
+
.then(() => {
|
|
580
|
+
// Do not return the result of callback
|
|
581
|
+
})
|
|
582
|
+
.finally(() => session.endSession());
|
|
605
583
|
}
|
|
606
584
|
|
|
607
585
|
/**
|
|
@@ -612,7 +590,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
|
|
|
612
590
|
* @param pipeline - An array of {@link https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/|aggregation pipeline stages} through which to pass change stream documents. This allows for filtering (using $match) and manipulating the change stream documents.
|
|
613
591
|
* @param options - Optional settings for the command
|
|
614
592
|
*/
|
|
615
|
-
watch<TSchema = Document>(
|
|
593
|
+
watch<TSchema extends Document = Document>(
|
|
616
594
|
pipeline: Document[] = [],
|
|
617
595
|
options: ChangeStreamOptions = {}
|
|
618
596
|
): ChangeStream<TSchema> {
|
|
@@ -32,7 +32,7 @@ export interface AddUserOptions extends CommandOperationOptions {
|
|
|
32
32
|
|
|
33
33
|
/** @internal */
|
|
34
34
|
export class AddUserOperation extends CommandOperation<Document> {
|
|
35
|
-
options: AddUserOptions;
|
|
35
|
+
override options: AddUserOptions;
|
|
36
36
|
db: Db;
|
|
37
37
|
username: string;
|
|
38
38
|
password?: string;
|
|
@@ -46,7 +46,11 @@ export class AddUserOperation extends CommandOperation<Document> {
|
|
|
46
46
|
this.options = options ?? {};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
execute(
|
|
49
|
+
override execute(
|
|
50
|
+
server: Server,
|
|
51
|
+
session: ClientSession | undefined,
|
|
52
|
+
callback: Callback<Document>
|
|
53
|
+
): void {
|
|
50
54
|
const db = this.db;
|
|
51
55
|
const username = this.username;
|
|
52
56
|
const password = this.password;
|
|
@@ -75,7 +79,14 @@ export class AddUserOperation extends CommandOperation<Document> {
|
|
|
75
79
|
roles = Array.isArray(options.roles) ? options.roles : [options.roles];
|
|
76
80
|
}
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
let topology;
|
|
83
|
+
try {
|
|
84
|
+
topology = getTopology(db);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
return callback(error);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const digestPassword = topology.lastHello().maxWireVersion >= 7;
|
|
79
90
|
|
|
80
91
|
let userPassword = password;
|
|
81
92
|
|
|
@@ -2,8 +2,7 @@ import type { Document } from '../bson';
|
|
|
2
2
|
import { MongoInvalidArgumentError } from '../error';
|
|
3
3
|
import type { Server } from '../sdam/server';
|
|
4
4
|
import type { ClientSession } from '../sessions';
|
|
5
|
-
import
|
|
6
|
-
import { maxWireVersion, MongoDBNamespace } from '../utils';
|
|
5
|
+
import { Callback, maxWireVersion, MongoDBNamespace } from '../utils';
|
|
7
6
|
import { CollationOptions, CommandOperation, CommandOperationOptions } from './command';
|
|
8
7
|
import { Aspect, defineAspects, Hint } from './operation';
|
|
9
8
|
|
|
@@ -31,12 +30,13 @@ export interface AggregateOptions extends CommandOperationOptions {
|
|
|
31
30
|
hint?: Hint;
|
|
32
31
|
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
|
|
33
32
|
let?: Document;
|
|
33
|
+
|
|
34
34
|
out?: string;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/** @internal */
|
|
38
38
|
export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
39
|
-
options: AggregateOptions;
|
|
39
|
+
override options: AggregateOptions;
|
|
40
40
|
target: string | typeof DB_AGGREGATE_COLLECTION;
|
|
41
41
|
pipeline: Document[];
|
|
42
42
|
hasWriteStage: boolean;
|
|
@@ -78,7 +78,7 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
get canRetryRead(): boolean {
|
|
81
|
+
override get canRetryRead(): boolean {
|
|
82
82
|
return !this.hasWriteStage;
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -86,7 +86,11 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
86
86
|
this.pipeline.push(stage);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
execute(
|
|
89
|
+
override execute(
|
|
90
|
+
server: Server,
|
|
91
|
+
session: ClientSession | undefined,
|
|
92
|
+
callback: Callback<T>
|
|
93
|
+
): void {
|
|
90
94
|
const options: AggregateOptions = this.options;
|
|
91
95
|
const serverWireVersion = maxWireVersion(server);
|
|
92
96
|
const command: Document = { aggregate: this.target, pipeline: this.pipeline };
|
|
@@ -117,6 +121,12 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
|
|
|
117
121
|
command.let = options.let;
|
|
118
122
|
}
|
|
119
123
|
|
|
124
|
+
// we check for undefined specifically here to allow falsy values
|
|
125
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
126
|
+
if (options.comment !== undefined) {
|
|
127
|
+
command.comment = options.comment;
|
|
128
|
+
}
|
|
129
|
+
|
|
120
130
|
command.cursor = options.cursor || {};
|
|
121
131
|
if (options.batchSize && !this.hasWriteStage) {
|
|
122
132
|
command.cursor.batchSize = options.batchSize;
|
|
@@ -12,7 +12,7 @@ import { AbstractOperation, Aspect, defineAspects } from './operation';
|
|
|
12
12
|
|
|
13
13
|
/** @internal */
|
|
14
14
|
export class BulkWriteOperation extends AbstractOperation<BulkWriteResult> {
|
|
15
|
-
options: BulkWriteOptions;
|
|
15
|
+
override options: BulkWriteOptions;
|
|
16
16
|
collection: Collection;
|
|
17
17
|
operations: AnyBulkWriteOperation[];
|
|
18
18
|
|
|
@@ -27,7 +27,11 @@ export class BulkWriteOperation extends AbstractOperation<BulkWriteResult> {
|
|
|
27
27
|
this.operations = operations;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
execute(
|
|
30
|
+
override execute(
|
|
31
|
+
server: Server,
|
|
32
|
+
session: ClientSession | undefined,
|
|
33
|
+
callback: Callback<BulkWriteResult>
|
|
34
|
+
): void {
|
|
31
35
|
const coll = this.collection;
|
|
32
36
|
const operations = this.operations;
|
|
33
37
|
const options = { ...this.options, ...this.bsonOptions, readPreference: this.readPreference };
|
|
@@ -11,7 +11,7 @@ export interface CollectionsOptions extends OperationOptions {
|
|
|
11
11
|
|
|
12
12
|
/** @internal */
|
|
13
13
|
export class CollectionsOperation extends AbstractOperation<Collection[]> {
|
|
14
|
-
options: CollectionsOptions;
|
|
14
|
+
override options: CollectionsOptions;
|
|
15
15
|
db: Db;
|
|
16
16
|
|
|
17
17
|
constructor(db: Db, options: CollectionsOptions) {
|
|
@@ -20,7 +20,11 @@ export class CollectionsOperation extends AbstractOperation<Collection[]> {
|
|
|
20
20
|
this.db = db;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
execute(
|
|
23
|
+
override execute(
|
|
24
|
+
server: Server,
|
|
25
|
+
session: ClientSession | undefined,
|
|
26
|
+
callback: Callback<Collection[]>
|
|
27
|
+
): void {
|
|
24
28
|
const db = this.db;
|
|
25
29
|
|
|
26
30
|
// Let's get the collection names
|
|
@@ -45,8 +45,15 @@ export interface CommandOperationOptions
|
|
|
45
45
|
/** Collation */
|
|
46
46
|
collation?: CollationOptions;
|
|
47
47
|
maxTimeMS?: number;
|
|
48
|
-
/**
|
|
49
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Comment to apply to the operation.
|
|
50
|
+
*
|
|
51
|
+
* In server versions pre-4.4, 'comment' must be string. A server
|
|
52
|
+
* error will be thrown if any other type is provided.
|
|
53
|
+
*
|
|
54
|
+
* In server versions 4.4 and above, 'comment' can be any valid BSON type.
|
|
55
|
+
*/
|
|
56
|
+
comment?: unknown;
|
|
50
57
|
/** Should retry failed writes */
|
|
51
58
|
retryWrites?: boolean;
|
|
52
59
|
|
|
@@ -68,8 +75,7 @@ export interface OperationParent {
|
|
|
68
75
|
|
|
69
76
|
/** @internal */
|
|
70
77
|
export abstract class CommandOperation<T> extends AbstractOperation<T> {
|
|
71
|
-
options: CommandOperationOptions;
|
|
72
|
-
ns: MongoDBNamespace;
|
|
78
|
+
override options: CommandOperationOptions;
|
|
73
79
|
readConcern?: ReadConcern;
|
|
74
80
|
writeConcern?: WriteConcern;
|
|
75
81
|
explain?: Explain;
|
|
@@ -106,16 +112,25 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
|
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
|
|
109
|
-
get canRetryWrite(): boolean {
|
|
115
|
+
override get canRetryWrite(): boolean {
|
|
110
116
|
if (this.hasAspect(Aspect.EXPLAINABLE)) {
|
|
111
117
|
return this.explain == null;
|
|
112
118
|
}
|
|
113
119
|
return true;
|
|
114
120
|
}
|
|
115
121
|
|
|
116
|
-
abstract execute(
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
abstract override execute(
|
|
123
|
+
server: Server,
|
|
124
|
+
session: ClientSession | undefined,
|
|
125
|
+
callback: Callback<T>
|
|
126
|
+
): void;
|
|
127
|
+
|
|
128
|
+
executeCommand(
|
|
129
|
+
server: Server,
|
|
130
|
+
session: ClientSession | undefined,
|
|
131
|
+
cmd: Document,
|
|
132
|
+
callback: Callback
|
|
133
|
+
): void {
|
|
119
134
|
// TODO: consider making this a non-enumerable property
|
|
120
135
|
this.server = server;
|
|
121
136
|
|
|
@@ -40,8 +40,15 @@ export function indexInformation(
|
|
|
40
40
|
// If we specified full information
|
|
41
41
|
const full = options.full == null ? false : options.full;
|
|
42
42
|
|
|
43
|
+
let topology;
|
|
44
|
+
try {
|
|
45
|
+
topology = getTopology(db);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return callback(error);
|
|
48
|
+
}
|
|
49
|
+
|
|
43
50
|
// Did the user destroy the topology
|
|
44
|
-
if (
|
|
51
|
+
if (topology.isDestroyed()) return callback(new MongoTopologyClosedError());
|
|
45
52
|
// Process all the results from the index command and collection
|
|
46
53
|
function processResults(indexes: any) {
|
|
47
54
|
// Contains all the information
|
package/src/operations/count.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface CountOptions extends CommandOperationOptions {
|
|
|
20
20
|
|
|
21
21
|
/** @internal */
|
|
22
22
|
export class CountOperation extends CommandOperation<number> {
|
|
23
|
-
options: CountOptions;
|
|
23
|
+
override options: CountOptions;
|
|
24
24
|
collectionName?: string;
|
|
25
25
|
query: Document;
|
|
26
26
|
|
|
@@ -32,7 +32,11 @@ export class CountOperation extends CommandOperation<number> {
|
|
|
32
32
|
this.query = filter;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
execute(
|
|
35
|
+
override execute(
|
|
36
|
+
server: Server,
|
|
37
|
+
session: ClientSession | undefined,
|
|
38
|
+
callback: Callback<number>
|
|
39
|
+
): void {
|
|
36
40
|
const options = this.options;
|
|
37
41
|
const cmd: Document = {
|
|
38
42
|
count: this.collectionName,
|
|
@@ -32,7 +32,11 @@ export class CountDocumentsOperation extends AggregateOperation<number> {
|
|
|
32
32
|
super(collection.s.namespace, pipeline, options);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
execute(
|
|
35
|
+
override execute(
|
|
36
|
+
server: Server,
|
|
37
|
+
session: ClientSession | undefined,
|
|
38
|
+
callback: Callback<number>
|
|
39
|
+
): void {
|
|
36
40
|
super.execute(server, session, (err, result) => {
|
|
37
41
|
if (err || !result) {
|
|
38
42
|
callback(err);
|
|
@@ -79,7 +79,7 @@ export interface CreateCollectionOptions extends CommandOperationOptions {
|
|
|
79
79
|
|
|
80
80
|
/** @internal */
|
|
81
81
|
export class CreateCollectionOperation extends CommandOperation<Collection> {
|
|
82
|
-
options: CreateCollectionOptions;
|
|
82
|
+
override options: CreateCollectionOptions;
|
|
83
83
|
db: Db;
|
|
84
84
|
name: string;
|
|
85
85
|
|
|
@@ -91,7 +91,11 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
|
|
|
91
91
|
this.name = name;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
execute(
|
|
94
|
+
override execute(
|
|
95
|
+
server: Server,
|
|
96
|
+
session: ClientSession | undefined,
|
|
97
|
+
callback: Callback<Collection>
|
|
98
|
+
): void {
|
|
95
99
|
const db = this.db;
|
|
96
100
|
const name = this.name;
|
|
97
101
|
const options = this.options;
|
package/src/operations/delete.ts
CHANGED
|
@@ -12,8 +12,6 @@ import { Aspect, defineAspects, Hint } from './operation';
|
|
|
12
12
|
export interface DeleteOptions extends CommandOperationOptions, WriteConcernOptions {
|
|
13
13
|
/** If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails. */
|
|
14
14
|
ordered?: boolean;
|
|
15
|
-
/** A user-provided comment to attach to this command */
|
|
16
|
-
comment?: string | Document;
|
|
17
15
|
/** Specifies the collation to use for the operation */
|
|
18
16
|
collation?: CollationOptions;
|
|
19
17
|
/** Specify that the update query should only consider plans using the hinted index */
|
|
@@ -43,13 +41,11 @@ export interface DeleteStatement {
|
|
|
43
41
|
collation?: CollationOptions;
|
|
44
42
|
/** A document or string that specifies the index to use to support the query predicate. */
|
|
45
43
|
hint?: Hint;
|
|
46
|
-
/** A user-provided comment to attach to this command */
|
|
47
|
-
comment?: string | Document;
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
/** @internal */
|
|
51
47
|
export class DeleteOperation extends CommandOperation<Document> {
|
|
52
|
-
options: DeleteOptions;
|
|
48
|
+
override options: DeleteOptions;
|
|
53
49
|
statements: DeleteStatement[];
|
|
54
50
|
|
|
55
51
|
constructor(ns: MongoDBNamespace, statements: DeleteStatement[], options: DeleteOptions) {
|
|
@@ -59,7 +55,7 @@ export class DeleteOperation extends CommandOperation<Document> {
|
|
|
59
55
|
this.statements = statements;
|
|
60
56
|
}
|
|
61
57
|
|
|
62
|
-
get canRetryWrite(): boolean {
|
|
58
|
+
override get canRetryWrite(): boolean {
|
|
63
59
|
if (super.canRetryWrite === false) {
|
|
64
60
|
return false;
|
|
65
61
|
}
|
|
@@ -67,7 +63,7 @@ export class DeleteOperation extends CommandOperation<Document> {
|
|
|
67
63
|
return this.statements.every(op => (op.limit != null ? op.limit > 0 : true));
|
|
68
64
|
}
|
|
69
65
|
|
|
70
|
-
execute(server: Server, session: ClientSession, callback: Callback): void {
|
|
66
|
+
override execute(server: Server, session: ClientSession | undefined, callback: Callback): void {
|
|
71
67
|
const options = this.options ?? {};
|
|
72
68
|
const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
|
|
73
69
|
const command: Document = {
|
|
@@ -80,6 +76,12 @@ export class DeleteOperation extends CommandOperation<Document> {
|
|
|
80
76
|
command.let = options.let;
|
|
81
77
|
}
|
|
82
78
|
|
|
79
|
+
// we check for undefined specifically here to allow falsy values
|
|
80
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
81
|
+
if (options.comment !== undefined) {
|
|
82
|
+
command.comment = options.comment;
|
|
83
|
+
}
|
|
84
|
+
|
|
83
85
|
if (options.explain != null && maxWireVersion(server) < 3) {
|
|
84
86
|
return callback
|
|
85
87
|
? callback(
|
|
@@ -111,7 +113,11 @@ export class DeleteOneOperation extends DeleteOperation {
|
|
|
111
113
|
super(collection.s.namespace, [makeDeleteStatement(filter, { ...options, limit: 1 })], options);
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
execute(
|
|
116
|
+
override execute(
|
|
117
|
+
server: Server,
|
|
118
|
+
session: ClientSession | undefined,
|
|
119
|
+
callback: Callback<DeleteResult>
|
|
120
|
+
): void {
|
|
115
121
|
super.execute(server, session, (err, res) => {
|
|
116
122
|
if (err || res == null) return callback(err);
|
|
117
123
|
if (res.code) return callback(new MongoServerError(res));
|
|
@@ -131,7 +137,11 @@ export class DeleteManyOperation extends DeleteOperation {
|
|
|
131
137
|
super(collection.s.namespace, [makeDeleteStatement(filter, options)], options);
|
|
132
138
|
}
|
|
133
139
|
|
|
134
|
-
execute(
|
|
140
|
+
override execute(
|
|
141
|
+
server: Server,
|
|
142
|
+
session: ClientSession | undefined,
|
|
143
|
+
callback: Callback<DeleteResult>
|
|
144
|
+
): void {
|
|
135
145
|
super.execute(server, session, (err, res) => {
|
|
136
146
|
if (err || res == null) return callback(err);
|
|
137
147
|
if (res.code) return callback(new MongoServerError(res));
|
|
@@ -167,10 +177,6 @@ export function makeDeleteStatement(
|
|
|
167
177
|
op.hint = options.hint;
|
|
168
178
|
}
|
|
169
179
|
|
|
170
|
-
if (options.comment) {
|
|
171
|
-
op.comment = options.comment;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
180
|
return op;
|
|
175
181
|
}
|
|
176
182
|
|
|
@@ -15,7 +15,7 @@ export type DistinctOptions = CommandOperationOptions;
|
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export class DistinctOperation extends CommandOperation<any[]> {
|
|
18
|
-
options: DistinctOptions;
|
|
18
|
+
override options: DistinctOptions;
|
|
19
19
|
collection: Collection;
|
|
20
20
|
/** Field of the document to find distinct values for. */
|
|
21
21
|
key: string;
|
|
@@ -39,7 +39,11 @@ export class DistinctOperation extends CommandOperation<any[]> {
|
|
|
39
39
|
this.query = query;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
execute(
|
|
42
|
+
override execute(
|
|
43
|
+
server: Server,
|
|
44
|
+
session: ClientSession | undefined,
|
|
45
|
+
callback: Callback<any[]>
|
|
46
|
+
): void {
|
|
43
47
|
const coll = this.collection;
|
|
44
48
|
const key = this.key;
|
|
45
49
|
const query = this.query;
|
package/src/operations/drop.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type DropCollectionOptions = CommandOperationOptions;
|
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
12
|
export class DropCollectionOperation extends CommandOperation<boolean> {
|
|
13
|
-
options: DropCollectionOptions;
|
|
13
|
+
override options: DropCollectionOptions;
|
|
14
14
|
name: string;
|
|
15
15
|
|
|
16
16
|
constructor(db: Db, name: string, options: DropCollectionOptions) {
|
|
@@ -19,7 +19,11 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
|
|
|
19
19
|
this.name = name;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
execute(
|
|
22
|
+
override execute(
|
|
23
|
+
server: Server,
|
|
24
|
+
session: ClientSession | undefined,
|
|
25
|
+
callback: Callback<boolean>
|
|
26
|
+
): void {
|
|
23
27
|
super.executeCommand(server, session, { drop: this.name }, (err, result) => {
|
|
24
28
|
if (err) return callback(err);
|
|
25
29
|
if (result.ok) return callback(undefined, true);
|
|
@@ -33,13 +37,17 @@ export type DropDatabaseOptions = CommandOperationOptions;
|
|
|
33
37
|
|
|
34
38
|
/** @internal */
|
|
35
39
|
export class DropDatabaseOperation extends CommandOperation<boolean> {
|
|
36
|
-
options: DropDatabaseOptions;
|
|
40
|
+
override options: DropDatabaseOptions;
|
|
37
41
|
|
|
38
42
|
constructor(db: Db, options: DropDatabaseOptions) {
|
|
39
43
|
super(db, options);
|
|
40
44
|
this.options = options;
|
|
41
45
|
}
|
|
42
|
-
execute(
|
|
46
|
+
override execute(
|
|
47
|
+
server: Server,
|
|
48
|
+
session: ClientSession | undefined,
|
|
49
|
+
callback: Callback<boolean>
|
|
50
|
+
): void {
|
|
43
51
|
super.executeCommand(server, session, { dropDatabase: 1 }, (err, result) => {
|
|
44
52
|
if (err) return callback(err);
|
|
45
53
|
if (result.ok) return callback(undefined, true);
|
|
@@ -19,7 +19,7 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
|
|
|
19
19
|
|
|
20
20
|
/** @internal */
|
|
21
21
|
export class EstimatedDocumentCountOperation extends CommandOperation<number> {
|
|
22
|
-
options: EstimatedDocumentCountOptions;
|
|
22
|
+
override options: EstimatedDocumentCountOptions;
|
|
23
23
|
collectionName: string;
|
|
24
24
|
|
|
25
25
|
constructor(collection: Collection, options: EstimatedDocumentCountOptions = {}) {
|
|
@@ -28,7 +28,11 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
|
|
|
28
28
|
this.collectionName = collection.collectionName;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
execute(
|
|
31
|
+
override execute(
|
|
32
|
+
server: Server,
|
|
33
|
+
session: ClientSession | undefined,
|
|
34
|
+
callback: Callback<number>
|
|
35
|
+
): void {
|
|
32
36
|
if (maxWireVersion(server) < 12) {
|
|
33
37
|
return this.executeLegacy(server, session, callback);
|
|
34
38
|
}
|
|
@@ -50,7 +54,11 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
|
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
executeLegacy(
|
|
57
|
+
executeLegacy(
|
|
58
|
+
server: Server,
|
|
59
|
+
session: ClientSession | undefined,
|
|
60
|
+
callback: Callback<number>
|
|
61
|
+
): void {
|
|
54
62
|
const cmd: Document = { count: this.collectionName };
|
|
55
63
|
|
|
56
64
|
if (typeof this.options.maxTimeMS === 'number') {
|