mongodb 6.18.0-dev.20250823.sha.c2166a50 → 6.18.0-dev.20250826.sha.66706f8e
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/lib/admin.js +2 -1
- package/lib/admin.js.map +1 -1
- package/lib/beta.d.ts +5 -5
- package/lib/collection.js.map +1 -1
- package/lib/cursor/run_command_cursor.js +2 -4
- package/lib/cursor/run_command_cursor.js.map +1 -1
- package/lib/db.js +1 -1
- package/lib/db.js.map +1 -1
- package/lib/mongo_client.js +25 -2
- package/lib/mongo_client.js.map +1 -1
- package/lib/operations/aggregate.js +1 -1
- package/lib/operations/aggregate.js.map +1 -1
- package/lib/operations/client_bulk_write/client_bulk_write.js +1 -1
- package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -1
- package/lib/operations/command.js +2 -67
- package/lib/operations/command.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 +1 -1
- package/lib/operations/delete.js.map +1 -1
- package/lib/operations/distinct.js +18 -26
- 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 +1 -1
- package/lib/operations/estimated_document_count.js.map +1 -1
- package/lib/operations/execute_operation.js +1 -5
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +1 -1
- package/lib/operations/find.js.map +1 -1
- package/lib/operations/find_and_modify.js +1 -1
- package/lib/operations/find_and_modify.js.map +1 -1
- package/lib/operations/get_more.js +1 -1
- package/lib/operations/get_more.js.map +1 -1
- package/lib/operations/indexes.js +3 -3
- package/lib/operations/indexes.js.map +1 -1
- package/lib/operations/insert.js +1 -1
- package/lib/operations/insert.js.map +1 -1
- package/lib/operations/kill_cursors.js +1 -1
- package/lib/operations/kill_cursors.js.map +1 -1
- package/lib/operations/list_collections.js +1 -1
- 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/operation.js +2 -10
- package/lib/operations/operation.js.map +1 -1
- package/lib/operations/profiling_level.js +14 -4
- package/lib/operations/profiling_level.js.map +1 -1
- package/lib/operations/remove_user.js +6 -2
- 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 +28 -32
- package/lib/operations/run_command.js.map +1 -1
- package/lib/operations/search_indexes/create.js +1 -1
- package/lib/operations/search_indexes/create.js.map +1 -1
- package/lib/operations/search_indexes/drop.js +1 -1
- package/lib/operations/search_indexes/drop.js.map +1 -1
- package/lib/operations/search_indexes/update.js +1 -1
- package/lib/operations/search_indexes/update.js.map +1 -1
- package/lib/operations/set_profiling_level.js +8 -4
- package/lib/operations/set_profiling_level.js.map +1 -1
- package/lib/operations/stats.js +4 -2
- package/lib/operations/stats.js.map +1 -1
- package/lib/operations/update.js +1 -1
- package/lib/operations/update.js.map +1 -1
- package/lib/operations/validate_collection.js +1 -1
- package/lib/operations/validate_collection.js.map +1 -1
- package/lib/sdam/server.js +2 -80
- package/lib/sdam/server.js.map +1 -1
- package/lib/sdam/topology.js +1 -1
- package/lib/sdam/topology.js.map +1 -1
- package/lib/sessions.js +3 -3
- package/lib/sessions.js.map +1 -1
- package/mongodb.d.ts +5 -5
- package/package.json +15 -15
- package/src/admin.ts +3 -2
- package/src/collection.ts +6 -0
- package/src/cursor/run_command_cursor.ts +4 -5
- package/src/db.ts +1 -1
- package/src/index.ts +1 -7
- package/src/mongo_client.ts +24 -9
- package/src/operations/aggregate.ts +2 -6
- package/src/operations/client_bulk_write/client_bulk_write.ts +2 -2
- package/src/operations/command.ts +2 -106
- package/src/operations/count.ts +2 -2
- package/src/operations/create_collection.ts +2 -2
- package/src/operations/delete.ts +2 -6
- package/src/operations/distinct.ts +23 -40
- package/src/operations/drop.ts +3 -3
- package/src/operations/estimated_document_count.ts +2 -2
- package/src/operations/execute_operation.ts +5 -14
- package/src/operations/find.ts +2 -6
- package/src/operations/find_and_modify.ts +2 -2
- package/src/operations/get_more.ts +2 -2
- package/src/operations/indexes.ts +4 -4
- package/src/operations/insert.ts +2 -2
- package/src/operations/kill_cursors.ts +2 -2
- package/src/operations/list_collections.ts +2 -2
- package/src/operations/list_databases.ts +2 -2
- package/src/operations/operation.ts +0 -19
- package/src/operations/profiling_level.ts +17 -11
- package/src/operations/remove_user.ts +9 -9
- package/src/operations/rename.ts +2 -2
- package/src/operations/run_command.ts +40 -68
- package/src/operations/search_indexes/create.ts +2 -2
- package/src/operations/search_indexes/drop.ts +2 -2
- package/src/operations/search_indexes/update.ts +2 -2
- package/src/operations/set_profiling_level.ts +13 -11
- package/src/operations/stats.ts +5 -10
- package/src/operations/update.ts +2 -6
- package/src/operations/validate_collection.ts +2 -2
- package/src/sdam/server.ts +4 -107
- package/src/sdam/topology.ts +1 -1
- package/src/sessions.ts +5 -4
package/src/operations/delete.ts
CHANGED
|
@@ -5,11 +5,7 @@ import { MongoCompatibilityError, MongoServerError } from '../error';
|
|
|
5
5
|
import type { ClientSession } from '../sessions';
|
|
6
6
|
import { type MongoDBCollectionNamespace, type MongoDBNamespace } from '../utils';
|
|
7
7
|
import { type WriteConcernOptions } from '../write_concern';
|
|
8
|
-
import {
|
|
9
|
-
type CollationOptions,
|
|
10
|
-
type CommandOperationOptions,
|
|
11
|
-
ModernizedCommandOperation
|
|
12
|
-
} from './command';
|
|
8
|
+
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
|
|
13
9
|
import { Aspect, defineAspects, type Hint } from './operation';
|
|
14
10
|
|
|
15
11
|
/** @public */
|
|
@@ -45,7 +41,7 @@ export interface DeleteStatement {
|
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
/** @internal */
|
|
48
|
-
export class DeleteOperation extends
|
|
44
|
+
export class DeleteOperation extends CommandOperation<Document> {
|
|
49
45
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
50
46
|
override options: DeleteOptions;
|
|
51
47
|
statements: DeleteStatement[];
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
2
4
|
import type { Collection } from '../collection';
|
|
3
|
-
import type { Server } from '../sdam/server';
|
|
4
|
-
import type { ClientSession } from '../sessions';
|
|
5
|
-
import { type TimeoutContext } from '../timeout';
|
|
6
|
-
import { decorateWithCollation, decorateWithReadConcern } from '../utils';
|
|
7
5
|
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
8
6
|
import { Aspect, defineAspects } from './operation';
|
|
9
7
|
|
|
@@ -27,7 +25,8 @@ export type DistinctOptions = CommandOperationOptions & {
|
|
|
27
25
|
* Return a list of distinct values for the given key across a collection.
|
|
28
26
|
* @internal
|
|
29
27
|
*/
|
|
30
|
-
export class DistinctOperation extends CommandOperation<any[]> {
|
|
28
|
+
export class DistinctOperation extends CommandOperation<any[] | Document> {
|
|
29
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
31
30
|
override options: DistinctOptions;
|
|
32
31
|
collection: Collection;
|
|
33
32
|
/** Field of the document to find distinct values for. */
|
|
@@ -56,48 +55,32 @@ export class DistinctOperation extends CommandOperation<any[]> {
|
|
|
56
55
|
return 'distinct' as const;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
override
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const coll = this.collection;
|
|
65
|
-
const key = this.key;
|
|
66
|
-
const query = this.query;
|
|
67
|
-
const options = this.options;
|
|
68
|
-
|
|
69
|
-
// Distinct command
|
|
70
|
-
const cmd: Document = {
|
|
71
|
-
distinct: coll.collectionName,
|
|
72
|
-
key: key,
|
|
73
|
-
query: query
|
|
58
|
+
override buildCommandDocument(_connection: Connection): Document {
|
|
59
|
+
const command: Document = {
|
|
60
|
+
distinct: this.collection.collectionName,
|
|
61
|
+
key: this.key,
|
|
62
|
+
query: this.query
|
|
74
63
|
};
|
|
75
|
-
|
|
76
|
-
// Add maxTimeMS if defined
|
|
77
|
-
if (typeof options.maxTimeMS === 'number') {
|
|
78
|
-
cmd.maxTimeMS = options.maxTimeMS;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
64
|
// we check for undefined specifically here to allow falsy values
|
|
82
65
|
// eslint-disable-next-line no-restricted-syntax
|
|
83
|
-
if (
|
|
84
|
-
|
|
66
|
+
if (this.options.comment !== undefined) {
|
|
67
|
+
command.comment = this.options.comment;
|
|
85
68
|
}
|
|
86
69
|
|
|
87
|
-
if (options.hint != null) {
|
|
88
|
-
|
|
70
|
+
if (this.options.hint != null) {
|
|
71
|
+
command.hint = this.options.hint;
|
|
89
72
|
}
|
|
90
73
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// Have we specified collation
|
|
95
|
-
decorateWithCollation(cmd, coll, options);
|
|
96
|
-
|
|
97
|
-
const result = await super.executeCommand(server, session, cmd, timeoutContext);
|
|
74
|
+
return command;
|
|
75
|
+
}
|
|
98
76
|
|
|
99
|
-
|
|
100
|
-
|
|
77
|
+
override handleOk(
|
|
78
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
79
|
+
): any[] | Document {
|
|
80
|
+
if (this.explain) {
|
|
81
|
+
return response.toObject(this.bsonOptions);
|
|
82
|
+
}
|
|
83
|
+
return response.toObject(this.bsonOptions).values;
|
|
101
84
|
}
|
|
102
85
|
}
|
|
103
86
|
|
package/src/operations/drop.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Db } from '../db';
|
|
|
6
6
|
import { MONGODB_ERROR_CODES } from '../error';
|
|
7
7
|
import type { ClientSession } from '../sessions';
|
|
8
8
|
import { TimeoutContext } from '../timeout';
|
|
9
|
-
import { type CommandOperationOptions
|
|
9
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
10
10
|
import { executeOperation } from './execute_operation';
|
|
11
11
|
import { Aspect, defineAspects } from './operation';
|
|
12
12
|
|
|
@@ -17,7 +17,7 @@ export interface DropCollectionOptions extends CommandOperationOptions {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
|
-
export class DropCollectionOperation extends
|
|
20
|
+
export class DropCollectionOperation extends CommandOperation<boolean> {
|
|
21
21
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
22
22
|
|
|
23
23
|
override options: DropCollectionOptions;
|
|
@@ -107,7 +107,7 @@ export async function dropCollections(
|
|
|
107
107
|
export type DropDatabaseOptions = CommandOperationOptions;
|
|
108
108
|
|
|
109
109
|
/** @internal */
|
|
110
|
-
export class DropDatabaseOperation extends
|
|
110
|
+
export class DropDatabaseOperation extends CommandOperation<boolean> {
|
|
111
111
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
112
112
|
override options: DropDatabaseOptions;
|
|
113
113
|
|
|
@@ -3,7 +3,7 @@ import type { Document } from '../bson';
|
|
|
3
3
|
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
4
4
|
import type { Collection } from '../collection';
|
|
5
5
|
import type { ClientSession } from '../sessions';
|
|
6
|
-
import { type CommandOperationOptions
|
|
6
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
7
7
|
import { Aspect, defineAspects } from './operation';
|
|
8
8
|
|
|
9
9
|
/** @public */
|
|
@@ -17,7 +17,7 @@ export interface EstimatedDocumentCountOptions extends CommandOperationOptions {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** @internal */
|
|
20
|
-
export class EstimatedDocumentCountOperation extends
|
|
20
|
+
export class EstimatedDocumentCountOperation extends CommandOperation<number> {
|
|
21
21
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
22
22
|
override options: EstimatedDocumentCountOptions;
|
|
23
23
|
collectionName: string;
|
|
@@ -27,18 +27,15 @@ import type { ClientSession } from '../sessions';
|
|
|
27
27
|
import { TimeoutContext } from '../timeout';
|
|
28
28
|
import { abortable, supportsRetryableWrites } from '../utils';
|
|
29
29
|
import { AggregateOperation } from './aggregate';
|
|
30
|
-
import { AbstractOperation, Aspect
|
|
30
|
+
import { AbstractOperation, Aspect } from './operation';
|
|
31
31
|
|
|
32
32
|
const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
|
|
33
33
|
const MMAPv1_RETRY_WRITES_ERROR_MESSAGE =
|
|
34
34
|
'This MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.';
|
|
35
35
|
|
|
36
|
-
type ResultTypeFromOperation<TOperation> =
|
|
37
|
-
TOperation
|
|
38
|
-
|
|
39
|
-
: TOperation extends AbstractOperation<infer K>
|
|
40
|
-
? K
|
|
41
|
-
: never;
|
|
36
|
+
type ResultTypeFromOperation<TOperation extends AbstractOperation> = ReturnType<
|
|
37
|
+
TOperation['handleOk']
|
|
38
|
+
>;
|
|
42
39
|
|
|
43
40
|
/**
|
|
44
41
|
* Executes the given operation with provided arguments.
|
|
@@ -235,8 +232,6 @@ async function tryOperation<T extends AbstractOperation, TResult = ResultTypeFro
|
|
|
235
232
|
let previousOperationError: MongoError | undefined;
|
|
236
233
|
let previousServer: ServerDescription | undefined;
|
|
237
234
|
|
|
238
|
-
const isModernOperation = operation instanceof ModernizedOperation;
|
|
239
|
-
|
|
240
235
|
for (let tries = 0; tries < maxTries; tries++) {
|
|
241
236
|
if (previousOperationError) {
|
|
242
237
|
if (hasWriteAspect && previousOperationError.code === MMAPv1_RETRY_WRITES_ERROR_CODE) {
|
|
@@ -290,12 +285,8 @@ async function tryOperation<T extends AbstractOperation, TResult = ResultTypeFro
|
|
|
290
285
|
operation.resetBatch();
|
|
291
286
|
}
|
|
292
287
|
|
|
293
|
-
if (!isModernOperation) {
|
|
294
|
-
return await operation.execute(server, session, timeoutContext);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
288
|
try {
|
|
298
|
-
const result = await server.
|
|
289
|
+
const result = await server.command(operation, timeoutContext);
|
|
299
290
|
return operation.handleOk(result);
|
|
300
291
|
} catch (error) {
|
|
301
292
|
return operation.handleError(error);
|
package/src/operations/find.ts
CHANGED
|
@@ -7,11 +7,7 @@ import type { ServerCommandOptions } from '../sdam/server';
|
|
|
7
7
|
import { formatSort, type Sort } from '../sort';
|
|
8
8
|
import { type TimeoutContext } from '../timeout';
|
|
9
9
|
import { type MongoDBNamespace, normalizeHintField } from '../utils';
|
|
10
|
-
import {
|
|
11
|
-
type CollationOptions,
|
|
12
|
-
type CommandOperationOptions,
|
|
13
|
-
ModernizedCommandOperation
|
|
14
|
-
} from './command';
|
|
10
|
+
import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
|
|
15
11
|
import { Aspect, defineAspects, type Hint } from './operation';
|
|
16
12
|
|
|
17
13
|
/**
|
|
@@ -90,7 +86,7 @@ export interface FindOneOptions extends FindOptions {
|
|
|
90
86
|
}
|
|
91
87
|
|
|
92
88
|
/** @internal */
|
|
93
|
-
export class FindOperation extends
|
|
89
|
+
export class FindOperation extends CommandOperation<CursorResponse> {
|
|
94
90
|
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
95
91
|
|
|
96
92
|
/**
|
|
@@ -8,7 +8,7 @@ import type { ClientSession } from '../sessions';
|
|
|
8
8
|
import { formatSort, type Sort, type SortForCmd } from '../sort';
|
|
9
9
|
import { decorateWithCollation, hasAtomicOperators } from '../utils';
|
|
10
10
|
import { type WriteConcern, type WriteConcernSettings } from '../write_concern';
|
|
11
|
-
import { type CommandOperationOptions
|
|
11
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
12
12
|
import { Aspect, defineAspects } from './operation';
|
|
13
13
|
|
|
14
14
|
/** @public */
|
|
@@ -120,7 +120,7 @@ function configureFindAndModifyCmdBaseUpdateOpts(
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
/** @internal */
|
|
123
|
-
export class FindAndModifyOperation extends
|
|
123
|
+
export class FindAndModifyOperation extends CommandOperation<Document> {
|
|
124
124
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
125
125
|
override options: FindOneAndReplaceOptions | FindOneAndUpdateOptions | FindOneAndDeleteOptions;
|
|
126
126
|
collection: Collection;
|
|
@@ -5,7 +5,7 @@ import { MongoRuntimeError } from '../error';
|
|
|
5
5
|
import type { Server, ServerCommandOptions } from '../sdam/server';
|
|
6
6
|
import { type TimeoutContext } from '../timeout';
|
|
7
7
|
import { maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
8
|
-
import { Aspect, defineAspects,
|
|
8
|
+
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
|
|
9
9
|
|
|
10
10
|
/** @internal */
|
|
11
11
|
export interface GetMoreOptions extends OperationOptions {
|
|
@@ -37,7 +37,7 @@ export interface GetMoreCommand {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** @internal */
|
|
40
|
-
export class GetMoreOperation extends
|
|
40
|
+
export class GetMoreOperation extends AbstractOperation<CursorResponse> {
|
|
41
41
|
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
42
42
|
cursorId: Long;
|
|
43
43
|
override options: GetMoreOptions;
|
|
@@ -8,8 +8,8 @@ import { type OneOrMore } from '../mongo_types';
|
|
|
8
8
|
import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
|
|
9
9
|
import {
|
|
10
10
|
type CollationOptions,
|
|
11
|
+
CommandOperation,
|
|
11
12
|
type CommandOperationOptions,
|
|
12
|
-
ModernizedCommandOperation,
|
|
13
13
|
type OperationParent
|
|
14
14
|
} from './command';
|
|
15
15
|
import { Aspect, defineAspects } from './operation';
|
|
@@ -242,7 +242,7 @@ type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
|
|
|
242
242
|
};
|
|
243
243
|
|
|
244
244
|
/** @internal */
|
|
245
|
-
export class CreateIndexesOperation extends
|
|
245
|
+
export class CreateIndexesOperation extends CommandOperation<string[]> {
|
|
246
246
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
247
247
|
override options: CreateIndexesOptions;
|
|
248
248
|
collectionName: string;
|
|
@@ -328,7 +328,7 @@ export class CreateIndexesOperation extends ModernizedCommandOperation<string[]>
|
|
|
328
328
|
export type DropIndexesOptions = CommandOperationOptions;
|
|
329
329
|
|
|
330
330
|
/** @internal */
|
|
331
|
-
export class DropIndexOperation extends
|
|
331
|
+
export class DropIndexOperation extends CommandOperation<Document> {
|
|
332
332
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
333
333
|
override options: DropIndexesOptions;
|
|
334
334
|
collection: Collection;
|
|
@@ -359,7 +359,7 @@ export type ListIndexesOptions = AbstractCursorOptions & {
|
|
|
359
359
|
};
|
|
360
360
|
|
|
361
361
|
/** @internal */
|
|
362
|
-
export class ListIndexesOperation extends
|
|
362
|
+
export class ListIndexesOperation extends CommandOperation<CursorResponse> {
|
|
363
363
|
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
364
364
|
/**
|
|
365
365
|
* @remarks WriteConcern can still be present on the options because
|
package/src/operations/insert.ts
CHANGED
|
@@ -7,10 +7,10 @@ import { MongoServerError } from '../error';
|
|
|
7
7
|
import type { InferIdType } from '../mongo_types';
|
|
8
8
|
import type { ClientSession } from '../sessions';
|
|
9
9
|
import { maybeAddIdToDocuments, type MongoDBNamespace } from '../utils';
|
|
10
|
-
import { type CommandOperationOptions
|
|
10
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
11
11
|
import { Aspect, defineAspects } from './operation';
|
|
12
12
|
/** @internal */
|
|
13
|
-
export class InsertOperation extends
|
|
13
|
+
export class InsertOperation extends CommandOperation<Document> {
|
|
14
14
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
15
15
|
override options: BulkWriteOptions;
|
|
16
16
|
|
|
@@ -6,7 +6,7 @@ import type { Server, ServerCommandOptions } from '../sdam/server';
|
|
|
6
6
|
import type { ClientSession } from '../sessions';
|
|
7
7
|
import { type TimeoutContext } from '../timeout';
|
|
8
8
|
import { type MongoDBNamespace } from '../utils';
|
|
9
|
-
import { Aspect, defineAspects,
|
|
9
|
+
import { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* https://www.mongodb.com/docs/manual/reference/command/killCursors/
|
|
@@ -18,7 +18,7 @@ interface KillCursorsCommand {
|
|
|
18
18
|
comment?: unknown;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export class KillCursorsOperation extends
|
|
21
|
+
export class KillCursorsOperation extends AbstractOperation<void> {
|
|
22
22
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
23
23
|
cursorId: Long;
|
|
24
24
|
|
|
@@ -5,7 +5,7 @@ import { type CursorTimeoutContext, type CursorTimeoutMode } from '../cursor/abs
|
|
|
5
5
|
import type { Db } from '../db';
|
|
6
6
|
import { type Abortable } from '../mongo_types';
|
|
7
7
|
import { maxWireVersion } from '../utils';
|
|
8
|
-
import { type CommandOperationOptions
|
|
8
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
9
9
|
import { Aspect, defineAspects } from './operation';
|
|
10
10
|
|
|
11
11
|
/** @public */
|
|
@@ -26,7 +26,7 @@ export interface ListCollectionsOptions
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/** @internal */
|
|
29
|
-
export class ListCollectionsOperation extends
|
|
29
|
+
export class ListCollectionsOperation extends CommandOperation<CursorResponse> {
|
|
30
30
|
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
31
31
|
/**
|
|
32
32
|
* @remarks WriteConcern can still be present on the options because
|
|
@@ -4,7 +4,7 @@ import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
|
4
4
|
import type { Db } from '../db';
|
|
5
5
|
import type { ClientSession } from '../sessions';
|
|
6
6
|
import { maxWireVersion, MongoDBNamespace } from '../utils';
|
|
7
|
-
import { type CommandOperationOptions
|
|
7
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
8
8
|
import { Aspect, defineAspects } from './operation';
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
@@ -26,7 +26,7 @@ export interface ListDatabasesOptions extends CommandOperationOptions {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/** @internal */
|
|
29
|
-
export class ListDatabasesOperation extends
|
|
29
|
+
export class ListDatabasesOperation extends CommandOperation<ListDatabasesResult> {
|
|
30
30
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
31
31
|
override options: ListDatabasesOptions;
|
|
32
32
|
|
|
@@ -87,12 +87,6 @@ export abstract class AbstractOperation<TResult = any> {
|
|
|
87
87
|
Command name should be stateless (should not use 'this' keyword) */
|
|
88
88
|
abstract get commandName(): string;
|
|
89
89
|
|
|
90
|
-
abstract execute(
|
|
91
|
-
server: Server,
|
|
92
|
-
session: ClientSession | undefined,
|
|
93
|
-
timeoutContext: TimeoutContext
|
|
94
|
-
): Promise<TResult>;
|
|
95
|
-
|
|
96
90
|
hasAspect(aspect: symbol): boolean {
|
|
97
91
|
const ctor = this.constructor as { aspects?: Set<symbol> };
|
|
98
92
|
if (ctor.aspects == null) {
|
|
@@ -126,21 +120,8 @@ export abstract class AbstractOperation<TResult = any> {
|
|
|
126
120
|
get canRetryWrite(): boolean {
|
|
127
121
|
return this.hasAspect(Aspect.RETRYABLE) && this.hasAspect(Aspect.WRITE_OPERATION);
|
|
128
122
|
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** @internal */
|
|
132
|
-
export abstract class ModernizedOperation<TResult> extends AbstractOperation<TResult> {
|
|
133
123
|
abstract SERVER_COMMAND_RESPONSE_TYPE: typeof MongoDBResponse;
|
|
134
124
|
|
|
135
|
-
/** this will never be used - but we must implement it to satisfy AbstractOperation's interface */
|
|
136
|
-
override execute(
|
|
137
|
-
_server: Server,
|
|
138
|
-
_session: ClientSession | undefined,
|
|
139
|
-
_timeoutContext: TimeoutContext
|
|
140
|
-
): Promise<TResult> {
|
|
141
|
-
throw new Error('cannot execute!!');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
125
|
/**
|
|
145
126
|
* Build a raw command document.
|
|
146
127
|
*/
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import { BSONType, type Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
1
4
|
import type { Db } from '../db';
|
|
2
5
|
import { MongoUnexpectedServerResponseError } from '../error';
|
|
3
|
-
import type { Server } from '../sdam/server';
|
|
4
|
-
import type { ClientSession } from '../sessions';
|
|
5
|
-
import { type TimeoutContext } from '../timeout';
|
|
6
6
|
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
9
|
export type ProfilingLevelOptions = CommandOperationOptions;
|
|
10
10
|
|
|
11
|
+
class ProfilingLevelResponse extends MongoDBResponse {
|
|
12
|
+
get was() {
|
|
13
|
+
return this.get('was', BSONType.int, true);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
11
17
|
/** @internal */
|
|
12
18
|
export class ProfilingLevelOperation extends CommandOperation<string> {
|
|
19
|
+
override SERVER_COMMAND_RESPONSE_TYPE = ProfilingLevelResponse;
|
|
13
20
|
override options: ProfilingLevelOptions;
|
|
14
21
|
|
|
15
22
|
constructor(db: Db, options: ProfilingLevelOptions) {
|
|
@@ -21,14 +28,13 @@ export class ProfilingLevelOperation extends CommandOperation<string> {
|
|
|
21
28
|
return 'profile' as const;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
override
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const was = doc.was;
|
|
31
|
+
override buildCommandDocument(_connection: Connection): Document {
|
|
32
|
+
return { profile: -1 };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): string {
|
|
36
|
+
if (response.ok === 1) {
|
|
37
|
+
const was = response.was;
|
|
32
38
|
if (was === 0) return 'off';
|
|
33
39
|
if (was === 1) return 'slow_only';
|
|
34
40
|
if (was === 2) return 'all';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { type Document } from '../bson';
|
|
2
|
+
import { type Connection } from '../cmap/connection';
|
|
3
|
+
import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
1
4
|
import type { Db } from '../db';
|
|
2
|
-
import type { Server } from '../sdam/server';
|
|
3
|
-
import type { ClientSession } from '../sessions';
|
|
4
|
-
import { type TimeoutContext } from '../timeout';
|
|
5
5
|
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
6
6
|
import { Aspect, defineAspects } from './operation';
|
|
7
7
|
|
|
@@ -10,6 +10,7 @@ export type RemoveUserOptions = CommandOperationOptions;
|
|
|
10
10
|
|
|
11
11
|
/** @internal */
|
|
12
12
|
export class RemoveUserOperation extends CommandOperation<boolean> {
|
|
13
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
13
14
|
override options: RemoveUserOptions;
|
|
14
15
|
username: string;
|
|
15
16
|
|
|
@@ -23,12 +24,11 @@ export class RemoveUserOperation extends CommandOperation<boolean> {
|
|
|
23
24
|
return 'dropUser' as const;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
override
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
await super.executeCommand(server, session, { dropUser: this.username }, timeoutContext);
|
|
27
|
+
override buildCommandDocument(_connection: Connection): Document {
|
|
28
|
+
return { dropUser: this.username };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override handleOk(_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): boolean {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/operations/rename.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
|
4
4
|
import { Collection } from '../collection';
|
|
5
5
|
import type { ClientSession } from '../sessions';
|
|
6
6
|
import { MongoDBNamespace } from '../utils';
|
|
7
|
-
import { type CommandOperationOptions
|
|
7
|
+
import { CommandOperation, type CommandOperationOptions } from './command';
|
|
8
8
|
import { Aspect, defineAspects } from './operation';
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
@@ -16,7 +16,7 @@ export interface RenameOptions extends CommandOperationOptions {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/** @internal */
|
|
19
|
-
export class RenameOperation extends
|
|
19
|
+
export class RenameOperation extends CommandOperation<Document> {
|
|
20
20
|
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
21
21
|
collection: Collection;
|
|
22
22
|
newName: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { type Abortable } from '..';
|
|
1
2
|
import type { BSONSerializeOptions, Document } from '../bson';
|
|
2
|
-
import { type
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { type Connection } from '../cmap/connection';
|
|
4
|
+
import { CursorResponse, MongoDBResponse } from '../cmap/wire_protocol/responses';
|
|
5
|
+
import { AbstractOperation } from '../operations/operation';
|
|
5
6
|
import type { ReadPreferenceLike } from '../read_preference';
|
|
6
|
-
import type {
|
|
7
|
+
import type { ServerCommandOptions } from '../sdam/server';
|
|
7
8
|
import type { ClientSession } from '../sessions';
|
|
8
9
|
import { type TimeoutContext } from '../timeout';
|
|
9
|
-
import { MongoDBNamespace } from '../utils';
|
|
10
|
-
import { AbstractOperation } from './operation';
|
|
10
|
+
import { type MongoDBNamespace } from '../utils';
|
|
11
11
|
|
|
12
12
|
/** @public */
|
|
13
13
|
export type RunCommandOptions = {
|
|
@@ -22,86 +22,58 @@ export type RunCommandOptions = {
|
|
|
22
22
|
timeoutMS?: number;
|
|
23
23
|
/** @internal */
|
|
24
24
|
omitMaxTimeMS?: boolean;
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @internal Hints to `executeOperation` that this operation should not unpin on an ended transaction
|
|
28
|
+
* This is only used by the driver for transaction commands
|
|
29
|
+
*/
|
|
30
|
+
bypassPinningCheck?: boolean;
|
|
31
|
+
} & BSONSerializeOptions &
|
|
32
|
+
Abortable;
|
|
26
33
|
|
|
27
34
|
/** @internal */
|
|
28
35
|
export class RunCommandOperation<T = Document> extends AbstractOperation<T> {
|
|
36
|
+
override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
|
|
29
37
|
command: Document;
|
|
30
|
-
override options: RunCommandOptions
|
|
38
|
+
override options: RunCommandOptions;
|
|
31
39
|
|
|
32
|
-
constructor(
|
|
33
|
-
parent: Db,
|
|
34
|
-
command: Document,
|
|
35
|
-
options: RunCommandOptions & { responseType?: MongoDBResponseConstructor }
|
|
36
|
-
) {
|
|
40
|
+
constructor(namespace: MongoDBNamespace, command: Document, options: RunCommandOptions) {
|
|
37
41
|
super(options);
|
|
38
42
|
this.command = command;
|
|
39
43
|
this.options = options;
|
|
40
|
-
this.ns =
|
|
44
|
+
this.ns = namespace.withCollection('$cmd');
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
override get commandName() {
|
|
44
48
|
return 'runCommand' as const;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
override
|
|
48
|
-
|
|
49
|
-
session: ClientSession | undefined,
|
|
50
|
-
timeoutContext: TimeoutContext
|
|
51
|
-
): Promise<T> {
|
|
52
|
-
this.server = server;
|
|
53
|
-
const res: TODO_NODE_3286 = await server.command(
|
|
54
|
-
this.ns,
|
|
55
|
-
this.command,
|
|
56
|
-
{
|
|
57
|
-
...this.options,
|
|
58
|
-
readPreference: this.readPreference,
|
|
59
|
-
session,
|
|
60
|
-
timeoutContext
|
|
61
|
-
},
|
|
62
|
-
this.options.responseType
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return res;
|
|
51
|
+
override buildCommand(_connection: Connection, _session?: ClientSession): Document {
|
|
52
|
+
return this.command;
|
|
66
53
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T> {
|
|
70
|
-
command: Document;
|
|
71
|
-
override options: RunCommandOptions & {
|
|
72
|
-
noResponse?: boolean;
|
|
73
|
-
bypassPinningCheck?: boolean;
|
|
74
|
-
};
|
|
75
54
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.command = command;
|
|
85
|
-
this.options = options;
|
|
86
|
-
this.ns = new MongoDBNamespace('admin', '$cmd');
|
|
55
|
+
override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
|
|
56
|
+
return {
|
|
57
|
+
...this.options,
|
|
58
|
+
session: this.session,
|
|
59
|
+
timeoutContext,
|
|
60
|
+
signal: this.options.signal,
|
|
61
|
+
readPreference: this.options.readPreference
|
|
62
|
+
};
|
|
87
63
|
}
|
|
64
|
+
}
|
|
88
65
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*
|
|
69
|
+
* A specialized subclass of RunCommandOperation for cursor-creating commands.
|
|
70
|
+
*/
|
|
71
|
+
export class RunCursorCommandOperation extends RunCommandOperation {
|
|
72
|
+
override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
|
|
92
73
|
|
|
93
|
-
override
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
): Promise<T> {
|
|
98
|
-
this.server = server;
|
|
99
|
-
const res: TODO_NODE_3286 = await server.command(this.ns, this.command, {
|
|
100
|
-
...this.options,
|
|
101
|
-
readPreference: this.readPreference,
|
|
102
|
-
session,
|
|
103
|
-
timeoutContext
|
|
104
|
-
});
|
|
105
|
-
return res;
|
|
74
|
+
override handleOk(
|
|
75
|
+
response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
|
|
76
|
+
): CursorResponse {
|
|
77
|
+
return response;
|
|
106
78
|
}
|
|
107
79
|
}
|