mongodb 6.18.0-dev.20250805.sha.ff9a7858 → 6.18.0-dev.20250808.sha.8e06e72a

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.
Files changed (98) hide show
  1. package/lib/beta.d.ts +2 -1
  2. package/lib/cmap/connection.js.map +1 -1
  3. package/lib/collection.js +5 -5
  4. package/lib/collection.js.map +1 -1
  5. package/lib/cursor/aggregation_cursor.js +2 -1
  6. package/lib/cursor/aggregation_cursor.js.map +1 -1
  7. package/lib/cursor/explainable_cursor.js +36 -0
  8. package/lib/cursor/explainable_cursor.js.map +1 -0
  9. package/lib/cursor/find_cursor.js +2 -1
  10. package/lib/cursor/find_cursor.js.map +1 -1
  11. package/lib/explain.js +1 -33
  12. package/lib/explain.js.map +1 -1
  13. package/lib/index.js +6 -6
  14. package/lib/index.js.map +1 -1
  15. package/lib/operations/aggregate.js +10 -8
  16. package/lib/operations/aggregate.js.map +1 -1
  17. package/lib/operations/client_bulk_write/client_bulk_write.js +9 -42
  18. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -1
  19. package/lib/operations/command.js +0 -9
  20. package/lib/operations/command.js.map +1 -1
  21. package/lib/operations/count.js +8 -4
  22. package/lib/operations/count.js.map +1 -1
  23. package/lib/operations/create_collection.js +17 -20
  24. package/lib/operations/create_collection.js.map +1 -1
  25. package/lib/operations/delete.js +16 -13
  26. package/lib/operations/delete.js.map +1 -1
  27. package/lib/operations/drop.js +13 -6
  28. package/lib/operations/drop.js.map +1 -1
  29. package/lib/operations/estimated_document_count.js +8 -4
  30. package/lib/operations/estimated_document_count.js.map +1 -1
  31. package/lib/operations/execute_operation.js +2 -1
  32. package/lib/operations/execute_operation.js.map +1 -1
  33. package/lib/operations/find.js +13 -24
  34. package/lib/operations/find.js.map +1 -1
  35. package/lib/operations/find_and_modify.js +53 -42
  36. package/lib/operations/find_and_modify.js.map +1 -1
  37. package/lib/operations/get_more.js +11 -12
  38. package/lib/operations/get_more.js.map +1 -1
  39. package/lib/operations/indexes.js +24 -15
  40. package/lib/operations/indexes.js.map +1 -1
  41. package/lib/operations/insert.js +0 -13
  42. package/lib/operations/insert.js.map +1 -1
  43. package/lib/operations/kill_cursors.js +14 -16
  44. package/lib/operations/kill_cursors.js.map +1 -1
  45. package/lib/operations/list_collections.js +8 -7
  46. package/lib/operations/list_collections.js.map +1 -1
  47. package/lib/operations/list_databases.js +6 -4
  48. package/lib/operations/list_databases.js.map +1 -1
  49. package/lib/operations/operation.js +0 -1
  50. package/lib/operations/operation.js.map +1 -1
  51. package/lib/operations/rename.js +11 -9
  52. package/lib/operations/rename.js.map +1 -1
  53. package/lib/operations/search_indexes/create.js +12 -9
  54. package/lib/operations/search_indexes/create.js.map +1 -1
  55. package/lib/operations/search_indexes/update.js +12 -5
  56. package/lib/operations/search_indexes/update.js.map +1 -1
  57. package/lib/operations/update.js +23 -20
  58. package/lib/operations/update.js.map +1 -1
  59. package/lib/operations/validate_collection.js +18 -19
  60. package/lib/operations/validate_collection.js.map +1 -1
  61. package/lib/sdam/server.js +31 -27
  62. package/lib/sdam/server.js.map +1 -1
  63. package/lib/sdam/topology.js +3 -2
  64. package/lib/sdam/topology.js.map +1 -1
  65. package/mongodb.d.ts +2 -1
  66. package/package.json +1 -1
  67. package/src/cmap/connection.ts +0 -1
  68. package/src/collection.ts +7 -22
  69. package/src/cursor/aggregation_cursor.ts +1 -1
  70. package/src/cursor/explainable_cursor.ts +51 -0
  71. package/src/cursor/find_cursor.ts +1 -1
  72. package/src/explain.ts +0 -49
  73. package/src/index.ts +2 -2
  74. package/src/operations/aggregate.ts +21 -22
  75. package/src/operations/client_bulk_write/client_bulk_write.ts +23 -67
  76. package/src/operations/command.ts +1 -12
  77. package/src/operations/count.ts +11 -11
  78. package/src/operations/create_collection.ts +22 -31
  79. package/src/operations/delete.ts +32 -36
  80. package/src/operations/drop.ts +18 -17
  81. package/src/operations/estimated_document_count.ts +10 -11
  82. package/src/operations/execute_operation.ts +9 -7
  83. package/src/operations/find.ts +28 -49
  84. package/src/operations/find_and_modify.ts +80 -56
  85. package/src/operations/get_more.ts +18 -20
  86. package/src/operations/indexes.ts +30 -34
  87. package/src/operations/insert.ts +0 -20
  88. package/src/operations/kill_cursors.ts +22 -23
  89. package/src/operations/list_collections.ts +15 -23
  90. package/src/operations/list_databases.ts +8 -17
  91. package/src/operations/operation.ts +0 -3
  92. package/src/operations/rename.ts +13 -16
  93. package/src/operations/search_indexes/create.ts +16 -16
  94. package/src/operations/search_indexes/update.ts +16 -11
  95. package/src/operations/update.ts +55 -54
  96. package/src/operations/validate_collection.ts +21 -29
  97. package/src/sdam/server.ts +33 -28
  98. package/src/sdam/topology.ts +4 -3
@@ -2,18 +2,16 @@ import type { Document } from '../bson';
2
2
  import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
3
3
  import { type AbstractCursorOptions, type CursorTimeoutMode } from '../cursor/abstract_cursor';
4
4
  import { MongoInvalidArgumentError } from '../error';
5
- import {
6
- decorateWithExplain,
7
- type ExplainOptions,
8
- validateExplainTimeoutOptions
9
- } from '../explain';
10
- import { ReadConcern } from '../read_concern';
11
- import type { Server } from '../sdam/server';
12
- import type { ClientSession } from '../sessions';
5
+ import { type ExplainOptions } from '../explain';
6
+ import type { ServerCommandOptions } from '../sdam/server';
13
7
  import { formatSort, type Sort } from '../sort';
14
8
  import { type TimeoutContext } from '../timeout';
15
9
  import { type MongoDBNamespace, normalizeHintField } from '../utils';
16
- import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
10
+ import {
11
+ type CollationOptions,
12
+ type CommandOperationOptions,
13
+ ModernizedCommandOperation
14
+ } from './command';
17
15
  import { Aspect, defineAspects, type Hint } from './operation';
18
16
 
19
17
  /**
@@ -92,7 +90,9 @@ export interface FindOneOptions extends FindOptions {
92
90
  }
93
91
 
94
92
  /** @internal */
95
- export class FindOperation extends CommandOperation<CursorResponse> {
93
+ export class FindOperation extends ModernizedCommandOperation<CursorResponse> {
94
+ override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
95
+
96
96
  /**
97
97
  * @remarks WriteConcern can still be present on the options because
98
98
  * we inherit options from the client/db/collection. The
@@ -116,39 +116,32 @@ export class FindOperation extends CommandOperation<CursorResponse> {
116
116
 
117
117
  // special case passing in an ObjectId as a filter
118
118
  this.filter = filter != null && filter._bsontype === 'ObjectId' ? { _id: filter } : filter;
119
+
120
+ this.SERVER_COMMAND_RESPONSE_TYPE = this.explain ? ExplainedCursorResponse : CursorResponse;
119
121
  }
120
122
 
121
123
  override get commandName() {
122
124
  return 'find' as const;
123
125
  }
124
126
 
125
- override async execute(
126
- server: Server,
127
- session: ClientSession | undefined,
128
- timeoutContext: TimeoutContext
129
- ): Promise<CursorResponse> {
130
- this.server = server;
131
-
132
- const options = this.options;
127
+ override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
128
+ return {
129
+ ...this.options,
130
+ ...this.bsonOptions,
131
+ documentsReturnedIn: 'firstBatch',
132
+ session: this.session,
133
+ timeoutContext
134
+ };
135
+ }
133
136
 
134
- let findCommand = makeFindCommand(this.ns, this.filter, options);
135
- if (this.explain) {
136
- validateExplainTimeoutOptions(this.options, this.explain);
137
- findCommand = decorateWithExplain(findCommand, this.explain);
138
- }
137
+ override handleOk(
138
+ response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
139
+ ): CursorResponse {
140
+ return response;
141
+ }
139
142
 
140
- return await server.command(
141
- this.ns,
142
- findCommand,
143
- {
144
- ...this.options,
145
- ...this.bsonOptions,
146
- documentsReturnedIn: 'firstBatch',
147
- session,
148
- timeoutContext
149
- },
150
- this.explain ? ExplainedCursorResponse : CursorResponse
151
- );
143
+ override buildCommandDocument(): Document {
144
+ return makeFindCommand(this.ns, this.filter, this.options);
152
145
  }
153
146
  }
154
147
 
@@ -217,15 +210,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
217
210
  findCommand.comment = options.comment;
218
211
  }
219
212
 
220
- if (typeof options.maxTimeMS === 'number') {
221
- findCommand.maxTimeMS = options.maxTimeMS;
222
- }
223
-
224
- const readConcern = ReadConcern.fromOptions(options);
225
- if (readConcern) {
226
- findCommand.readConcern = readConcern.toJSON();
227
- }
228
-
229
213
  if (options.max) {
230
214
  findCommand.max = options.max;
231
215
  }
@@ -263,11 +247,6 @@ function makeFindCommand(ns: MongoDBNamespace, filter: Document, options: FindOp
263
247
  if (typeof options.allowPartialResults === 'boolean') {
264
248
  findCommand.allowPartialResults = options.allowPartialResults;
265
249
  }
266
-
267
- if (options.collation) {
268
- findCommand.collation = options.collation;
269
- }
270
-
271
250
  if (typeof options.allowDiskUse === 'boolean') {
272
251
  findCommand.allowDiskUse = options.allowDiskUse;
273
252
  }
@@ -1,14 +1,14 @@
1
+ import { type Connection } from '..';
1
2
  import type { Document } from '../bson';
3
+ import { MongoDBResponse } from '../cmap/wire_protocol/responses';
2
4
  import type { Collection } from '../collection';
3
5
  import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
4
6
  import { ReadPreference } from '../read_preference';
5
- import type { Server } from '../sdam/server';
6
7
  import type { ClientSession } from '../sessions';
7
8
  import { formatSort, type Sort, type SortForCmd } from '../sort';
8
- import { type TimeoutContext } from '../timeout';
9
- import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
9
+ import { decorateWithCollation, hasAtomicOperators } from '../utils';
10
10
  import { type WriteConcern, type WriteConcernSettings } from '../write_concern';
11
- import { CommandOperation, type CommandOperationOptions } from './command';
11
+ import { type CommandOperationOptions, ModernizedCommandOperation } from './command';
12
12
  import { Aspect, defineAspects } from './operation';
13
13
 
14
14
  /** @public */
@@ -120,9 +120,9 @@ function configureFindAndModifyCmdBaseUpdateOpts(
120
120
  }
121
121
 
122
122
  /** @internal */
123
- export class FindAndModifyOperation extends CommandOperation<Document> {
123
+ export class FindAndModifyOperation extends ModernizedCommandOperation<Document> {
124
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
124
125
  override options: FindOneAndReplaceOptions | FindOneAndUpdateOptions | FindOneAndDeleteOptions;
125
- cmdBase: FindAndModifyCmdBase;
126
126
  collection: Collection;
127
127
  query: Document;
128
128
  doc?: Document;
@@ -133,8 +133,26 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
133
133
  options: FindOneAndReplaceOptions | FindOneAndUpdateOptions | FindOneAndDeleteOptions
134
134
  ) {
135
135
  super(collection, options);
136
- this.options = options ?? {};
137
- this.cmdBase = {
136
+ this.options = options;
137
+ // force primary read preference
138
+ this.readPreference = ReadPreference.primary;
139
+
140
+ this.collection = collection;
141
+ this.query = query;
142
+ }
143
+
144
+ override get commandName() {
145
+ return 'findAndModify' as const;
146
+ }
147
+
148
+ override buildCommandDocument(
149
+ _connection: Connection,
150
+ _session?: ClientSession
151
+ ): Document & FindAndModifyCmdBase {
152
+ const options = this.options;
153
+ const command: Document & FindAndModifyCmdBase = {
154
+ findAndModify: this.collection.collectionName,
155
+ query: this.query,
138
156
  remove: false,
139
157
  new: false,
140
158
  upsert: false
@@ -144,77 +162,51 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
144
162
 
145
163
  const sort = formatSort(options.sort);
146
164
  if (sort) {
147
- this.cmdBase.sort = sort;
165
+ command.sort = sort;
148
166
  }
149
167
 
150
168
  if (options.projection) {
151
- this.cmdBase.fields = options.projection;
169
+ command.fields = options.projection;
152
170
  }
153
171
 
154
172
  if (options.maxTimeMS) {
155
- this.cmdBase.maxTimeMS = options.maxTimeMS;
173
+ command.maxTimeMS = options.maxTimeMS;
156
174
  }
157
175
 
158
176
  // Decorate the findAndModify command with the write Concern
159
177
  if (options.writeConcern) {
160
- this.cmdBase.writeConcern = options.writeConcern;
178
+ command.writeConcern = options.writeConcern;
161
179
  }
162
180
 
163
181
  if (options.let) {
164
- this.cmdBase.let = options.let;
182
+ command.let = options.let;
165
183
  }
166
184
 
167
185
  // we check for undefined specifically here to allow falsy values
168
186
  // eslint-disable-next-line no-restricted-syntax
169
187
  if (options.comment !== undefined) {
170
- this.cmdBase.comment = options.comment;
188
+ command.comment = options.comment;
171
189
  }
172
190
 
173
- // force primary read preference
174
- this.readPreference = ReadPreference.primary;
175
-
176
- this.collection = collection;
177
- this.query = query;
178
- }
179
-
180
- override get commandName() {
181
- return 'findAndModify' as const;
182
- }
183
-
184
- override async execute(
185
- server: Server,
186
- session: ClientSession | undefined,
187
- timeoutContext: TimeoutContext
188
- ): Promise<Document> {
189
- const coll = this.collection;
190
- const query = this.query;
191
- const options = { ...this.options, ...this.bsonOptions };
192
-
193
- // Create findAndModify command object
194
- const cmd: Document = {
195
- findAndModify: coll.collectionName,
196
- query: query,
197
- ...this.cmdBase
198
- };
199
-
200
- decorateWithCollation(cmd, coll, options);
191
+ decorateWithCollation(command, this.collection, options);
201
192
 
202
193
  if (options.hint) {
203
- // TODO: once this method becomes a CommandOperation we will have the server
204
- // in place to check.
205
194
  const unacknowledgedWrite = this.writeConcern?.w === 0;
206
- if (unacknowledgedWrite || maxWireVersion(server) < 8) {
195
+ if (unacknowledgedWrite) {
207
196
  throw new MongoCompatibilityError(
208
197
  'The current topology does not support a hint on findAndModify commands'
209
198
  );
210
199
  }
211
200
 
212
- cmd.hint = options.hint;
201
+ command.hint = options.hint;
213
202
  }
214
203
 
215
- // Execute the command
216
- const result = await super.executeCommand(server, session, cmd, timeoutContext);
217
- return options.includeResultMetadata ? result : (result.value ?? null);
204
+ return command;
205
+ }
206
+
207
+ override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
208
+ const result = super.handleOk(response);
209
+ return this.options.includeResultMetadata ? result : (result.value ?? null);
218
210
  }
219
211
  }
220
212
 
@@ -227,12 +219,21 @@ export class FindOneAndDeleteOperation extends FindAndModifyOperation {
227
219
  }
228
220
 
229
221
  super(collection, filter, options);
230
- this.cmdBase.remove = true;
222
+ }
223
+
224
+ override buildCommandDocument(
225
+ connection: Connection,
226
+ session?: ClientSession
227
+ ): Document & FindAndModifyCmdBase {
228
+ const document = super.buildCommandDocument(connection, session);
229
+ document.remove = true;
230
+ return document;
231
231
  }
232
232
  }
233
233
 
234
234
  /** @internal */
235
235
  export class FindOneAndReplaceOperation extends FindAndModifyOperation {
236
+ private replacement: Document;
236
237
  constructor(
237
238
  collection: Collection,
238
239
  filter: Document,
@@ -252,13 +253,25 @@ export class FindOneAndReplaceOperation extends FindAndModifyOperation {
252
253
  }
253
254
 
254
255
  super(collection, filter, options);
255
- this.cmdBase.update = replacement;
256
- configureFindAndModifyCmdBaseUpdateOpts(this.cmdBase, options);
256
+ this.replacement = replacement;
257
+ }
258
+
259
+ override buildCommandDocument(
260
+ connection: Connection,
261
+ session?: ClientSession
262
+ ): Document & FindAndModifyCmdBase {
263
+ const document = super.buildCommandDocument(connection, session);
264
+ document.update = this.replacement;
265
+ configureFindAndModifyCmdBaseUpdateOpts(document, this.options);
266
+ return document;
257
267
  }
258
268
  }
259
269
 
260
270
  /** @internal */
261
271
  export class FindOneAndUpdateOperation extends FindAndModifyOperation {
272
+ override options: FindOneAndUpdateOptions;
273
+
274
+ private update: Document;
262
275
  constructor(
263
276
  collection: Collection,
264
277
  filter: Document,
@@ -278,12 +291,23 @@ export class FindOneAndUpdateOperation extends FindAndModifyOperation {
278
291
  }
279
292
 
280
293
  super(collection, filter, options);
281
- this.cmdBase.update = update;
282
- configureFindAndModifyCmdBaseUpdateOpts(this.cmdBase, options);
294
+ this.update = update;
295
+ this.options = options;
296
+ }
283
297
 
284
- if (options.arrayFilters) {
285
- this.cmdBase.arrayFilters = options.arrayFilters;
298
+ override buildCommandDocument(
299
+ connection: Connection,
300
+ session?: ClientSession
301
+ ): Document & FindAndModifyCmdBase {
302
+ const document = super.buildCommandDocument(connection, session);
303
+ document.update = this.update;
304
+ configureFindAndModifyCmdBaseUpdateOpts(document, this.options);
305
+
306
+ if (this.options.arrayFilters) {
307
+ document.arrayFilters = this.options.arrayFilters;
286
308
  }
309
+
310
+ return document;
287
311
  }
288
312
  }
289
313
 
@@ -1,11 +1,11 @@
1
- import type { Long } from '../bson';
1
+ import type { Document, Long } from '../bson';
2
+ import { type Connection } from '../cmap/connection';
2
3
  import { CursorResponse } from '../cmap/wire_protocol/responses';
3
4
  import { MongoRuntimeError } from '../error';
4
- import type { Server } from '../sdam/server';
5
- import type { ClientSession } from '../sessions';
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 { AbstractOperation, Aspect, defineAspects, type OperationOptions } from './operation';
8
+ import { Aspect, defineAspects, ModernizedOperation, type OperationOptions } from './operation';
9
9
 
10
10
  /** @internal */
11
11
  export interface GetMoreOptions extends OperationOptions {
@@ -37,7 +37,8 @@ export interface GetMoreCommand {
37
37
  }
38
38
 
39
39
  /** @internal */
40
- export class GetMoreOperation extends AbstractOperation {
40
+ export class GetMoreOperation extends ModernizedOperation<CursorResponse> {
41
+ override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
41
42
  cursorId: Long;
42
43
  override options: GetMoreOptions;
43
44
 
@@ -53,19 +54,8 @@ export class GetMoreOperation extends AbstractOperation {
53
54
  override get commandName() {
54
55
  return 'getMore' as const;
55
56
  }
56
- /**
57
- * Although there is a server already associated with the get more operation, the signature
58
- * for execute passes a server so we will just use that one.
59
- */
60
- override async execute(
61
- server: Server,
62
- _session: ClientSession | undefined,
63
- timeoutContext: TimeoutContext
64
- ): Promise<CursorResponse> {
65
- if (server !== this.server) {
66
- throw new MongoRuntimeError('Getmore must run on the same server operation began on');
67
- }
68
57
 
58
+ override buildCommand(connection: Connection): Document {
69
59
  if (this.cursorId == null || this.cursorId.isZero()) {
70
60
  throw new MongoRuntimeError('Unable to iterate cursor with no id');
71
61
  }
@@ -92,18 +82,26 @@ export class GetMoreOperation extends AbstractOperation {
92
82
 
93
83
  // we check for undefined specifically here to allow falsy values
94
84
  // eslint-disable-next-line no-restricted-syntax
95
- if (this.options.comment !== undefined && maxWireVersion(server) >= 9) {
85
+ if (this.options.comment !== undefined && maxWireVersion(connection) >= 9) {
96
86
  getMoreCmd.comment = this.options.comment;
97
87
  }
98
88
 
99
- const commandOptions = {
89
+ return getMoreCmd;
90
+ }
91
+
92
+ override buildOptions(timeoutContext: TimeoutContext): ServerCommandOptions {
93
+ return {
100
94
  returnFieldSelector: null,
101
95
  documentsReturnedIn: 'nextBatch',
102
96
  timeoutContext,
103
97
  ...this.options
104
98
  };
99
+ }
105
100
 
106
- return await server.command(this.ns, getMoreCmd, commandOptions, CursorResponse);
101
+ override handleOk(
102
+ response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
103
+ ): CursorResponse {
104
+ return response;
107
105
  }
108
106
  }
109
107
 
@@ -1,17 +1,15 @@
1
1
  import type { Document } from '../bson';
2
- import { CursorResponse } from '../cmap/wire_protocol/responses';
2
+ import { type Connection } from '../cmap/connection';
3
+ import { CursorResponse, MongoDBResponse } from '../cmap/wire_protocol/responses';
3
4
  import type { Collection } from '../collection';
4
5
  import { type AbstractCursorOptions } from '../cursor/abstract_cursor';
5
6
  import { MongoCompatibilityError } from '../error';
6
7
  import { type OneOrMore } from '../mongo_types';
7
- import type { Server } from '../sdam/server';
8
- import type { ClientSession } from '../sessions';
9
- import { type TimeoutContext } from '../timeout';
10
8
  import { isObject, maxWireVersion, type MongoDBNamespace } from '../utils';
11
9
  import {
12
10
  type CollationOptions,
13
- CommandOperation,
14
11
  type CommandOperationOptions,
12
+ ModernizedCommandOperation,
15
13
  type OperationParent
16
14
  } from './command';
17
15
  import { Aspect, defineAspects } from './operation';
@@ -244,7 +242,8 @@ type ResolvedIndexDescription = Omit<IndexDescription, 'key' | 'version'> & {
244
242
  };
245
243
 
246
244
  /** @internal */
247
- export class CreateIndexesOperation extends CommandOperation<string[]> {
245
+ export class CreateIndexesOperation extends ModernizedCommandOperation<string[]> {
246
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
248
247
  override options: CreateIndexesOptions;
249
248
  collectionName: string;
250
249
  indexes: ReadonlyArray<ResolvedIndexDescription>;
@@ -258,6 +257,8 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
258
257
  super(parent, options);
259
258
 
260
259
  this.options = options ?? {};
260
+ // collation is set on each index, it should not be defined at the root
261
+ this.options.collation = undefined;
261
262
  this.collectionName = collectionName;
262
263
  this.indexes = indexes.map((userIndex: IndexDescription): ResolvedIndexDescription => {
263
264
  // Ensure the key is a Map to preserve index key ordering
@@ -271,6 +272,7 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
271
272
  key
272
273
  };
273
274
  });
275
+ this.ns = parent.s.namespace;
274
276
  }
275
277
 
276
278
  static fromIndexDescriptionArray(
@@ -297,15 +299,11 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
297
299
  return 'createIndexes';
298
300
  }
299
301
 
300
- override async execute(
301
- server: Server,
302
- session: ClientSession | undefined,
303
- timeoutContext: TimeoutContext
304
- ): Promise<string[]> {
302
+ override buildCommandDocument(connection: Connection): Document {
305
303
  const options = this.options;
306
304
  const indexes = this.indexes;
307
305
 
308
- const serverWireVersion = maxWireVersion(server);
306
+ const serverWireVersion = maxWireVersion(connection);
309
307
 
310
308
  const cmd: Document = { createIndexes: this.collectionName, indexes };
311
309
 
@@ -317,13 +315,11 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
317
315
  }
318
316
  cmd.commitQuorum = options.commitQuorum;
319
317
  }
318
+ return cmd;
319
+ }
320
320
 
321
- // collation is set on each index, it should not be defined at the root
322
- this.options.collation = undefined;
323
-
324
- await super.executeCommand(server, session, cmd, timeoutContext);
325
-
326
- const indexNames = indexes.map(index => index.name || '');
321
+ override handleOk(_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): string[] {
322
+ const indexNames = this.indexes.map(index => index.name || '');
327
323
  return indexNames;
328
324
  }
329
325
  }
@@ -332,7 +328,8 @@ export class CreateIndexesOperation extends CommandOperation<string[]> {
332
328
  export type DropIndexesOptions = CommandOperationOptions;
333
329
 
334
330
  /** @internal */
335
- export class DropIndexOperation extends CommandOperation<Document> {
331
+ export class DropIndexOperation extends ModernizedCommandOperation<Document> {
332
+ override SERVER_COMMAND_RESPONSE_TYPE = MongoDBResponse;
336
333
  override options: DropIndexesOptions;
337
334
  collection: Collection;
338
335
  indexName: string;
@@ -343,19 +340,15 @@ export class DropIndexOperation extends CommandOperation<Document> {
343
340
  this.options = options ?? {};
344
341
  this.collection = collection;
345
342
  this.indexName = indexName;
343
+ this.ns = collection.fullNamespace;
346
344
  }
347
345
 
348
346
  override get commandName() {
349
347
  return 'dropIndexes' as const;
350
348
  }
351
349
 
352
- override async execute(
353
- server: Server,
354
- session: ClientSession | undefined,
355
- timeoutContext: TimeoutContext
356
- ): Promise<Document> {
357
- const cmd = { dropIndexes: this.collection.collectionName, index: this.indexName };
358
- return await super.executeCommand(server, session, cmd, timeoutContext);
350
+ override buildCommandDocument(_connection: Connection): Document {
351
+ return { dropIndexes: this.collection.collectionName, index: this.indexName };
359
352
  }
360
353
  }
361
354
 
@@ -366,7 +359,8 @@ export type ListIndexesOptions = AbstractCursorOptions & {
366
359
  };
367
360
 
368
361
  /** @internal */
369
- export class ListIndexesOperation extends CommandOperation<CursorResponse> {
362
+ export class ListIndexesOperation extends ModernizedCommandOperation<CursorResponse> {
363
+ override SERVER_COMMAND_RESPONSE_TYPE = CursorResponse;
370
364
  /**
371
365
  * @remarks WriteConcern can still be present on the options because
372
366
  * we inherit options from the client/db/collection. The
@@ -389,12 +383,8 @@ export class ListIndexesOperation extends CommandOperation<CursorResponse> {
389
383
  return 'listIndexes' as const;
390
384
  }
391
385
 
392
- override async execute(
393
- server: Server,
394
- session: ClientSession | undefined,
395
- timeoutContext: TimeoutContext
396
- ): Promise<CursorResponse> {
397
- const serverWireVersion = maxWireVersion(server);
386
+ override buildCommandDocument(connection: Connection): Document {
387
+ const serverWireVersion = maxWireVersion(connection);
398
388
 
399
389
  const cursor = this.options.batchSize ? { batchSize: this.options.batchSize } : {};
400
390
 
@@ -406,7 +396,13 @@ export class ListIndexesOperation extends CommandOperation<CursorResponse> {
406
396
  command.comment = this.options.comment;
407
397
  }
408
398
 
409
- return await super.executeCommand(server, session, command, timeoutContext, CursorResponse);
399
+ return command;
400
+ }
401
+
402
+ override handleOk(
403
+ response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>
404
+ ): CursorResponse {
405
+ return response;
410
406
  }
411
407
  }
412
408
 
@@ -5,9 +5,7 @@ import { MongoDBResponse } from '../cmap/wire_protocol/responses';
5
5
  import type { Collection } from '../collection';
6
6
  import { MongoServerError } from '../error';
7
7
  import type { InferIdType } from '../mongo_types';
8
- import type { Server } from '../sdam/server';
9
8
  import type { ClientSession } from '../sessions';
10
- import { type TimeoutContext } from '../timeout';
11
9
  import { maybeAddIdToDocuments, type MongoDBNamespace } from '../utils';
12
10
  import { type CommandOperationOptions, ModernizedCommandOperation } from './command';
13
11
  import { Aspect, defineAspects } from './operation';
@@ -73,24 +71,6 @@ export class InsertOneOperation extends InsertOperation {
73
71
  super(collection.s.namespace, [maybeAddIdToDocuments(collection, doc, options)], options);
74
72
  }
75
73
 
76
- override async execute(
77
- server: Server,
78
- session: ClientSession | undefined,
79
- timeoutContext: TimeoutContext
80
- ): Promise<InsertOneResult> {
81
- const res = await super.execute(server, session, timeoutContext);
82
- if (res.code) throw new MongoServerError(res);
83
- if (res.writeErrors) {
84
- // This should be a WriteError but we can't change it now because of error hierarchy
85
- throw new MongoServerError(res.writeErrors[0]);
86
- }
87
-
88
- return {
89
- acknowledged: this.writeConcern?.w !== 0,
90
- insertedId: this.documents[0]._id
91
- };
92
- }
93
-
94
74
  override handleOk(response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
95
75
  const res = super.handleOk(response);
96
76
  if (res.code) throw new MongoServerError(res);