mongodb 6.5.0 → 6.6.0-dev.20240504.sha.2609953

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 (207) hide show
  1. package/README.md +9 -9
  2. package/lib/admin.js +9 -9
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bson.js +33 -22
  5. package/lib/bson.js.map +1 -1
  6. package/lib/bulk/common.js +13 -12
  7. package/lib/bulk/common.js.map +1 -1
  8. package/lib/change_stream.js +28 -18
  9. package/lib/change_stream.js.map +1 -1
  10. package/lib/client-side-encryption/auto_encrypter.js +2 -2
  11. package/lib/client-side-encryption/auto_encrypter.js.map +1 -1
  12. package/lib/client-side-encryption/client_encryption.js +6 -6
  13. package/lib/client-side-encryption/client_encryption.js.map +1 -1
  14. package/lib/client-side-encryption/providers/aws.js +13 -10
  15. package/lib/client-side-encryption/providers/aws.js.map +1 -1
  16. package/lib/client-side-encryption/providers/azure.js +6 -3
  17. package/lib/client-side-encryption/providers/azure.js.map +1 -1
  18. package/lib/cmap/auth/aws_temporary_credentials.js +140 -0
  19. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -0
  20. package/lib/cmap/auth/gssapi.js +7 -6
  21. package/lib/cmap/auth/gssapi.js.map +1 -1
  22. package/lib/cmap/auth/mongodb_aws.js +8 -101
  23. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  24. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +1 -1
  25. package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -1
  26. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js +2 -1
  27. package/lib/cmap/auth/mongodb_oidc/callback_lock_cache.js.map +1 -1
  28. package/lib/cmap/auth/mongodb_oidc/service_workflow.js +1 -1
  29. package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -1
  30. package/lib/cmap/auth/scram.js +2 -2
  31. package/lib/cmap/auth/scram.js.map +1 -1
  32. package/lib/cmap/commands.js +24 -111
  33. package/lib/cmap/commands.js.map +1 -1
  34. package/lib/cmap/connect.js +4 -4
  35. package/lib/cmap/connect.js.map +1 -1
  36. package/lib/cmap/connection.js +61 -36
  37. package/lib/cmap/connection.js.map +1 -1
  38. package/lib/cmap/connection_pool.js +22 -13
  39. package/lib/cmap/connection_pool.js.map +1 -1
  40. package/lib/cmap/handshake/client_metadata.js +2 -2
  41. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  42. package/lib/cmap/wire_protocol/compression.js +8 -8
  43. package/lib/cmap/wire_protocol/compression.js.map +1 -1
  44. package/lib/cmap/wire_protocol/on_demand/document.js +218 -0
  45. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -0
  46. package/lib/cmap/wire_protocol/responses.js +184 -0
  47. package/lib/cmap/wire_protocol/responses.js.map +1 -0
  48. package/lib/collection.js +42 -38
  49. package/lib/collection.js.map +1 -1
  50. package/lib/connection_string.js +4 -6
  51. package/lib/connection_string.js.map +1 -1
  52. package/lib/cursor/abstract_cursor.js +76 -43
  53. package/lib/cursor/abstract_cursor.js.map +1 -1
  54. package/lib/cursor/aggregation_cursor.js +16 -33
  55. package/lib/cursor/aggregation_cursor.js.map +1 -1
  56. package/lib/cursor/find_cursor.js +36 -18
  57. package/lib/cursor/find_cursor.js.map +1 -1
  58. package/lib/cursor/run_command_cursor.js +3 -2
  59. package/lib/cursor/run_command_cursor.js.map +1 -1
  60. package/lib/db.js +15 -19
  61. package/lib/db.js.map +1 -1
  62. package/lib/deps.js +31 -26
  63. package/lib/deps.js.map +1 -1
  64. package/lib/encrypter.js +14 -5
  65. package/lib/encrypter.js.map +1 -1
  66. package/lib/error.js +4 -3
  67. package/lib/error.js.map +1 -1
  68. package/lib/gridfs/download.js +19 -14
  69. package/lib/gridfs/download.js.map +1 -1
  70. package/lib/gridfs/index.js.map +1 -1
  71. package/lib/gridfs/upload.js +6 -1
  72. package/lib/gridfs/upload.js.map +1 -1
  73. package/lib/index.js.map +1 -1
  74. package/lib/mongo_client.js +11 -7
  75. package/lib/mongo_client.js.map +1 -1
  76. package/lib/mongo_logger.js +3 -0
  77. package/lib/mongo_logger.js.map +1 -1
  78. package/lib/operations/aggregate.js +2 -1
  79. package/lib/operations/aggregate.js.map +1 -1
  80. package/lib/operations/command.js +1 -1
  81. package/lib/operations/command.js.map +1 -1
  82. package/lib/operations/create_collection.js +1 -1
  83. package/lib/operations/create_collection.js.map +1 -1
  84. package/lib/operations/delete.js +4 -3
  85. package/lib/operations/delete.js.map +1 -1
  86. package/lib/operations/drop.js +1 -1
  87. package/lib/operations/drop.js.map +1 -1
  88. package/lib/operations/execute_operation.js +23 -8
  89. package/lib/operations/execute_operation.js.map +1 -1
  90. package/lib/operations/find.js +4 -4
  91. package/lib/operations/find.js.map +1 -1
  92. package/lib/operations/get_more.js +2 -1
  93. package/lib/operations/get_more.js.map +1 -1
  94. package/lib/operations/indexes.js +29 -121
  95. package/lib/operations/indexes.js.map +1 -1
  96. package/lib/operations/insert.js +3 -3
  97. package/lib/operations/insert.js.map +1 -1
  98. package/lib/operations/kill_cursors.js +3 -1
  99. package/lib/operations/kill_cursors.js.map +1 -1
  100. package/lib/operations/list_collections.js +1 -1
  101. package/lib/operations/list_collections.js.map +1 -1
  102. package/lib/operations/list_databases.js +1 -1
  103. package/lib/operations/list_databases.js.map +1 -1
  104. package/lib/operations/operation.js.map +1 -1
  105. package/lib/operations/run_command.js +4 -2
  106. package/lib/operations/run_command.js.map +1 -1
  107. package/lib/operations/search_indexes/create.js.map +1 -1
  108. package/lib/operations/stats.js +1 -1
  109. package/lib/operations/stats.js.map +1 -1
  110. package/lib/operations/update.js +1 -1
  111. package/lib/operations/update.js.map +1 -1
  112. package/lib/sdam/common.js.map +1 -1
  113. package/lib/sdam/monitor.js +139 -42
  114. package/lib/sdam/monitor.js.map +1 -1
  115. package/lib/sdam/server.js +5 -15
  116. package/lib/sdam/server.js.map +1 -1
  117. package/lib/sdam/server_description.js +1 -0
  118. package/lib/sdam/server_description.js.map +1 -1
  119. package/lib/sdam/server_selection.js +1 -1
  120. package/lib/sdam/server_selection.js.map +1 -1
  121. package/lib/sdam/srv_polling.js +2 -1
  122. package/lib/sdam/srv_polling.js.map +1 -1
  123. package/lib/sdam/topology.js +67 -54
  124. package/lib/sdam/topology.js.map +1 -1
  125. package/lib/sdam/topology_description.js +10 -0
  126. package/lib/sdam/topology_description.js.map +1 -1
  127. package/lib/sessions.js +133 -93
  128. package/lib/sessions.js.map +1 -1
  129. package/lib/timeout.js +77 -0
  130. package/lib/timeout.js.map +1 -0
  131. package/lib/utils.js +61 -28
  132. package/lib/utils.js.map +1 -1
  133. package/mongodb.d.ts +150 -38
  134. package/package.json +17 -14
  135. package/src/admin.ts +9 -9
  136. package/src/bson.ts +14 -0
  137. package/src/bulk/common.ts +3 -2
  138. package/src/change_stream.ts +39 -30
  139. package/src/client-side-encryption/auto_encrypter.ts +2 -2
  140. package/src/client-side-encryption/client_encryption.ts +6 -6
  141. package/src/client-side-encryption/providers/aws.ts +17 -10
  142. package/src/client-side-encryption/providers/azure.ts +5 -3
  143. package/src/cmap/auth/aws_temporary_credentials.ts +169 -0
  144. package/src/cmap/auth/gssapi.ts +9 -11
  145. package/src/cmap/auth/mongodb_aws.ts +19 -126
  146. package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +1 -1
  147. package/src/cmap/auth/mongodb_oidc/callback_lock_cache.ts +2 -1
  148. package/src/cmap/auth/mongodb_oidc/service_workflow.ts +1 -1
  149. package/src/cmap/auth/scram.ts +2 -2
  150. package/src/cmap/commands.ts +28 -132
  151. package/src/cmap/connect.ts +4 -4
  152. package/src/cmap/connection.ts +107 -43
  153. package/src/cmap/connection_pool.ts +32 -29
  154. package/src/cmap/handshake/client_metadata.ts +2 -5
  155. package/src/cmap/wire_protocol/compression.ts +11 -13
  156. package/src/cmap/wire_protocol/on_demand/document.ts +338 -0
  157. package/src/cmap/wire_protocol/responses.ts +237 -0
  158. package/src/collection.ts +87 -58
  159. package/src/connection_string.ts +9 -7
  160. package/src/cursor/abstract_cursor.ts +102 -38
  161. package/src/cursor/aggregation_cursor.ts +32 -34
  162. package/src/cursor/find_cursor.ts +33 -21
  163. package/src/cursor/list_search_indexes_cursor.ts +1 -1
  164. package/src/cursor/run_command_cursor.ts +3 -2
  165. package/src/db.ts +42 -21
  166. package/src/deps.ts +52 -40
  167. package/src/encrypter.ts +14 -5
  168. package/src/error.ts +9 -3
  169. package/src/gridfs/download.ts +19 -31
  170. package/src/gridfs/index.ts +2 -0
  171. package/src/gridfs/upload.ts +11 -8
  172. package/src/index.ts +13 -5
  173. package/src/mongo_client.ts +21 -15
  174. package/src/mongo_logger.ts +3 -0
  175. package/src/mongo_types.ts +1 -1
  176. package/src/operations/aggregate.ts +2 -1
  177. package/src/operations/command.ts +1 -1
  178. package/src/operations/create_collection.ts +7 -2
  179. package/src/operations/delete.ts +4 -3
  180. package/src/operations/drop.ts +1 -1
  181. package/src/operations/execute_operation.ts +29 -10
  182. package/src/operations/find.ts +13 -14
  183. package/src/operations/get_more.ts +9 -1
  184. package/src/operations/indexes.ts +103 -176
  185. package/src/operations/insert.ts +2 -2
  186. package/src/operations/kill_cursors.ts +3 -2
  187. package/src/operations/list_collections.ts +5 -1
  188. package/src/operations/list_databases.ts +1 -1
  189. package/src/operations/operation.ts +3 -0
  190. package/src/operations/run_command.ts +6 -4
  191. package/src/operations/search_indexes/create.ts +4 -1
  192. package/src/operations/stats.ts +1 -1
  193. package/src/operations/update.ts +7 -7
  194. package/src/sdam/common.ts +8 -2
  195. package/src/sdam/monitor.ts +178 -61
  196. package/src/sdam/server.ts +27 -20
  197. package/src/sdam/server_description.ts +8 -3
  198. package/src/sdam/server_selection.ts +2 -3
  199. package/src/sdam/srv_polling.ts +3 -2
  200. package/src/sdam/topology.ts +114 -117
  201. package/src/sdam/topology_description.ts +14 -4
  202. package/src/sessions.ts +168 -148
  203. package/src/timeout.ts +96 -0
  204. package/src/utils.ts +85 -32
  205. package/lib/operations/common_functions.js +0 -38
  206. package/lib/operations/common_functions.js.map +0 -1
  207. package/src/operations/common_functions.ts +0 -79
@@ -1,7 +1,6 @@
1
1
  import { promises as fs } from 'fs';
2
2
  import type { TcpNetConnectOpts } from 'net';
3
3
  import type { ConnectionOptions as TLSConnectionOptions, TLSSocketOptions } from 'tls';
4
- import { promisify } from 'util';
5
4
 
6
5
  import { type BSONSerializeOptions, type Document, resolveBSONOptions } from './bson';
7
6
  import { ChangeStream, type ChangeStreamDocument, type ChangeStreamOptions } from './change_stream';
@@ -50,7 +49,8 @@ import {
50
49
  isHostMatch,
51
50
  type MongoDBNamespace,
52
51
  ns,
53
- resolveOptions
52
+ resolveOptions,
53
+ squashError
54
54
  } from './utils';
55
55
  import type { W, WriteConcern, WriteConcernSettings } from './write_concern';
56
56
 
@@ -120,7 +120,7 @@ export type SupportedNodeConnectionOptions = SupportedTLSConnectionOptions &
120
120
  export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeConnectionOptions {
121
121
  /** Specifies the name of the replica set, if the mongod is a member of a replica set. */
122
122
  replicaSet?: string;
123
- /** @internal This option is in development and currently has no behaviour. */
123
+ /** @internal TODO(NODE-5688): This option is in development and currently has no behaviour. */
124
124
  timeoutMS?: number;
125
125
  /** Enables or disables TLS/SSL for the connection. */
126
126
  tls?: boolean;
@@ -469,7 +469,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
469
469
  */
470
470
  async connect(): Promise<this> {
471
471
  if (this.connectionLock) {
472
- return this.connectionLock;
472
+ return await this.connectionLock;
473
473
  }
474
474
 
475
475
  try {
@@ -550,7 +550,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
550
550
 
551
551
  const topologyConnect = async () => {
552
552
  try {
553
- await promisify(callback => this.topology?.connect(options, callback))();
553
+ await this.topology?.connect(options);
554
554
  } catch (error) {
555
555
  this.topology?.close();
556
556
  throw error;
@@ -600,13 +600,17 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
600
600
  if (servers.length !== 0) {
601
601
  const endSessions = Array.from(this.s.sessionPool.sessions, ({ id }) => id);
602
602
  if (endSessions.length !== 0) {
603
- await executeOperation(
604
- this,
605
- new RunAdminCommandOperation(
606
- { endSessions },
607
- { readPreference: ReadPreference.primaryPreferred, noResponse: true }
608
- )
609
- ).catch(() => null); // outcome does not matter;
603
+ try {
604
+ await executeOperation(
605
+ this,
606
+ new RunAdminCommandOperation(
607
+ { endSessions },
608
+ { readPreference: ReadPreference.primaryPreferred, noResponse: true }
609
+ )
610
+ );
611
+ } catch (error) {
612
+ squashError(error);
613
+ }
610
614
  }
611
615
  }
612
616
 
@@ -656,7 +660,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
656
660
  */
657
661
  static async connect(url: string, options?: MongoClientOptions): Promise<MongoClient> {
658
662
  const client = new this(url, options);
659
- return client.connect();
663
+ return await client.connect();
660
664
  }
661
665
 
662
666
  /**
@@ -718,8 +722,8 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
718
722
  } finally {
719
723
  try {
720
724
  await session.endSession();
721
- } catch {
722
- // We are not concerned with errors from endSession()
725
+ } catch (error) {
726
+ squashError(error);
723
727
  }
724
728
  }
725
729
  }
@@ -893,4 +897,6 @@ export interface MongoOptions
893
897
  * TODO: NODE-5671 - remove internal flag
894
898
  */
895
899
  mongodbLogPath?: 'stderr' | 'stdout' | MongoDBLogWritable;
900
+ /** @internal TODO(NODE-5688): make this public */
901
+ timeoutMS?: number;
896
902
  }
@@ -836,7 +836,9 @@ export class MongoLogger {
836
836
 
837
837
  if (isPromiseLike(this.pendingLog)) {
838
838
  this.pendingLog = this.pendingLog
839
+ // eslint-disable-next-line github/no-then
839
840
  .then(() => this.logDestination.write(logMessage))
841
+ // eslint-disable-next-line github/no-then
840
842
  .then(this.clearPendingLog.bind(this), this.logWriteFailureHandler.bind(this));
841
843
  return;
842
844
  }
@@ -844,6 +846,7 @@ export class MongoLogger {
844
846
  try {
845
847
  const logResult = this.logDestination.write(logMessage);
846
848
  if (isPromiseLike(logResult)) {
849
+ // eslint-disable-next-line github/no-then
847
850
  this.pendingLog = logResult.then(
848
851
  this.clearPendingLog.bind(this),
849
852
  this.logWriteFailureHandler.bind(this)
@@ -219,7 +219,7 @@ export type NotAcceptedFields<TSchema, FieldType> = {
219
219
  /** @public */
220
220
  export type OnlyFieldsOfType<TSchema, FieldType = any, AssignableType = FieldType> = IsAny<
221
221
  TSchema[keyof TSchema],
222
- Record<string, FieldType>,
222
+ AssignableType extends FieldType ? Record<string, FieldType> : Record<string, AssignableType>,
223
223
  AcceptedFields<TSchema, FieldType, AssignableType> &
224
224
  NotAcceptedFields<TSchema, FieldType> &
225
225
  Record<string, AssignableType>
@@ -134,7 +134,8 @@ export class AggregateOperation<T = Document> extends CommandOperation<T> {
134
134
  command.cursor.batchSize = options.batchSize;
135
135
  }
136
136
 
137
- return super.executeCommand(server, session, command) as TODO_NODE_3286;
137
+ const res: TODO_NODE_3286 = await super.executeCommand(server, session, command);
138
+ return res;
138
139
  }
139
140
  }
140
141
 
@@ -152,6 +152,6 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
152
152
  cmd = decorateWithExplain(cmd, this.explain);
153
153
  }
154
154
 
155
- return server.command(this.ns, cmd, options);
155
+ return await server.command(this.ns, cmd, options);
156
156
  }
157
157
  }
@@ -10,7 +10,7 @@ import type { PkFactory } from '../mongo_client';
10
10
  import type { Server } from '../sdam/server';
11
11
  import type { ClientSession } from '../sessions';
12
12
  import { CommandOperation, type CommandOperationOptions } from './command';
13
- import { CreateIndexOperation } from './indexes';
13
+ import { CreateIndexesOperation } from './indexes';
14
14
  import { Aspect, defineAspects } from './operation';
15
15
 
16
16
  const ILLEGAL_COMMAND_FIELDS = new Set([
@@ -167,7 +167,12 @@ export class CreateCollectionOperation extends CommandOperation<Collection> {
167
167
 
168
168
  if (encryptedFields) {
169
169
  // Create the required index for queryable encryption support.
170
- const createIndexOp = new CreateIndexOperation(db, name, { __safeContent__: 1 }, {});
170
+ const createIndexOp = CreateIndexesOperation.fromIndexSpecification(
171
+ db,
172
+ name,
173
+ { __safeContent__: 1 },
174
+ {}
175
+ );
171
176
  await createIndexOp.execute(server, session);
172
177
  }
173
178
 
@@ -95,7 +95,8 @@ export class DeleteOperation extends CommandOperation<DeleteResult> {
95
95
  }
96
96
  }
97
97
 
98
- return super.executeCommand(server, session, command) as TODO_NODE_3286;
98
+ const res: TODO_NODE_3286 = await super.executeCommand(server, session, command);
99
+ return res;
99
100
  }
100
101
  }
101
102
 
@@ -108,7 +109,7 @@ export class DeleteOneOperation extends DeleteOperation {
108
109
  server: Server,
109
110
  session: ClientSession | undefined
110
111
  ): Promise<DeleteResult> {
111
- const res = (await super.execute(server, session)) as TODO_NODE_3286;
112
+ const res: TODO_NODE_3286 = await super.execute(server, session);
112
113
  if (this.explain) return res;
113
114
  if (res.code) throw new MongoServerError(res);
114
115
  if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
@@ -128,7 +129,7 @@ export class DeleteManyOperation extends DeleteOperation {
128
129
  server: Server,
129
130
  session: ClientSession | undefined
130
131
  ): Promise<DeleteResult> {
131
- const res = (await super.execute(server, session)) as TODO_NODE_3286;
132
+ const res: TODO_NODE_3286 = await super.execute(server, session);
132
133
  if (this.explain) return res;
133
134
  if (res.code) throw new MongoServerError(res);
134
135
  if (res.writeErrors) throw new MongoServerError(res.writeErrors[0]);
@@ -69,7 +69,7 @@ export class DropCollectionOperation extends CommandOperation<boolean> {
69
69
  }
70
70
  }
71
71
 
72
- return this.executeWithoutEncryptedFieldsCheck(server, session);
72
+ return await this.executeWithoutEncryptedFieldsCheck(server, session);
73
73
  }
74
74
 
75
75
  private async executeWithoutEncryptedFieldsCheck(
@@ -1,4 +1,5 @@
1
1
  import type { Document } from '../bson';
2
+ import { type CursorResponse } from '../cmap/wire_protocol/responses';
2
3
  import {
3
4
  isRetryableReadError,
4
5
  isRetryableWriteError,
@@ -26,7 +27,7 @@ import {
26
27
  } from '../sdam/server_selection';
27
28
  import type { Topology } from '../sdam/topology';
28
29
  import type { ClientSession } from '../sessions';
29
- import { supportsRetryableWrites } from '../utils';
30
+ import { squashError, supportsRetryableWrites } from '../utils';
30
31
  import { AbstractOperation, Aspect } from './operation';
31
32
 
32
33
  const MMAPv1_RETRY_WRITES_ERROR_CODE = MONGODB_ERROR_CODES.IllegalOperation;
@@ -44,7 +45,7 @@ export interface ExecutionResult {
44
45
  /** The session used for this operation, may be implicitly created */
45
46
  session?: ClientSession;
46
47
  /** The raw server response for the operation */
47
- response: Document;
48
+ response: Document | CursorResponse;
48
49
  }
49
50
 
50
51
  /**
@@ -110,11 +111,23 @@ export async function executeOperation<
110
111
  } else if (session.client !== client) {
111
112
  throw new MongoInvalidArgumentError('ClientSession must be from the same MongoClient');
112
113
  }
114
+ if (session.explicit && session?.timeoutMS != null && operation.options.timeoutMS != null) {
115
+ throw new MongoInvalidArgumentError(
116
+ 'Do not specify timeoutMS on operation if already specified on an explicit session'
117
+ );
118
+ }
113
119
 
114
120
  const readPreference = operation.readPreference ?? ReadPreference.primary;
115
121
  const inTransaction = !!session?.inTransaction();
116
122
 
117
- if (inTransaction && !readPreference.equals(ReadPreference.primary)) {
123
+ const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
124
+ const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
125
+
126
+ if (
127
+ inTransaction &&
128
+ !readPreference.equals(ReadPreference.primary) &&
129
+ (hasReadAspect || operation.commandName === 'runCommand')
130
+ ) {
118
131
  throw new MongoTransactionError(
119
132
  `Read preference in a transaction must be primary, not: ${readPreference.mode}`
120
133
  );
@@ -139,14 +152,14 @@ export async function executeOperation<
139
152
  selector = readPreference;
140
153
  }
141
154
 
142
- const server = await topology.selectServerAsync(selector, {
155
+ const server = await topology.selectServer(selector, {
143
156
  session,
144
157
  operationName: operation.commandName
145
158
  });
146
159
 
147
160
  if (session == null) {
148
161
  // No session also means it is not retryable, early exit
149
- return operation.execute(server, undefined);
162
+ return await operation.execute(server, undefined);
150
163
  }
151
164
 
152
165
  if (!operation.hasAspect(Aspect.RETRYABLE)) {
@@ -155,7 +168,11 @@ export async function executeOperation<
155
168
  return await operation.execute(server, session);
156
169
  } finally {
157
170
  if (session?.owner != null && session.owner === owner) {
158
- await session.endSession().catch(() => null);
171
+ try {
172
+ await session.endSession();
173
+ } catch (error) {
174
+ squashError(error);
175
+ }
159
176
  }
160
177
  }
161
178
  }
@@ -168,8 +185,6 @@ export async function executeOperation<
168
185
  supportsRetryableWrites(server) &&
169
186
  operation.canRetryWrite;
170
187
 
171
- const hasReadAspect = operation.hasAspect(Aspect.READ_OPERATION);
172
- const hasWriteAspect = operation.hasAspect(Aspect.WRITE_OPERATION);
173
188
  const willRetry = (hasReadAspect && willRetryRead) || (hasWriteAspect && willRetryWrite);
174
189
 
175
190
  if (hasWriteAspect && willRetryWrite) {
@@ -191,7 +206,11 @@ export async function executeOperation<
191
206
  throw operationError;
192
207
  } finally {
193
208
  if (session?.owner != null && session.owner === owner) {
194
- await session.endSession().catch(() => null);
209
+ try {
210
+ await session.endSession();
211
+ } catch (error) {
212
+ squashError(error);
213
+ }
195
214
  }
196
215
  }
197
216
  }
@@ -244,7 +263,7 @@ async function retryOperation<
244
263
  }
245
264
 
246
265
  // select a new server, and attempt to retry the operation
247
- const server = await topology.selectServerAsync(selector, {
266
+ const server = await topology.selectServer(selector, {
248
267
  session,
249
268
  operationName: operation.commandName,
250
269
  previousServer
@@ -1,5 +1,4 @@
1
1
  import type { Document } from '../bson';
2
- import type { Collection } from '../collection';
3
2
  import { MongoInvalidArgumentError } from '../error';
4
3
  import { ReadConcern } from '../read_concern';
5
4
  import type { Server } from '../sdam/server';
@@ -77,13 +76,8 @@ export class FindOperation extends CommandOperation<Document> {
77
76
  override options: FindOptions & { writeConcern?: never };
78
77
  filter: Document;
79
78
 
80
- constructor(
81
- collection: Collection | undefined,
82
- ns: MongoDBNamespace,
83
- filter: Document = {},
84
- options: FindOptions = {}
85
- ) {
86
- super(collection, options);
79
+ constructor(ns: MongoDBNamespace, filter: Document = {}, options: FindOptions = {}) {
80
+ super(undefined, options);
87
81
 
88
82
  this.options = { ...options };
89
83
  delete this.options.writeConcern;
@@ -111,12 +105,17 @@ export class FindOperation extends CommandOperation<Document> {
111
105
  findCommand = decorateWithExplain(findCommand, this.explain);
112
106
  }
113
107
 
114
- return server.command(this.ns, findCommand, {
115
- ...this.options,
116
- ...this.bsonOptions,
117
- documentsReturnedIn: 'firstBatch',
118
- session
119
- });
108
+ return await server.command(
109
+ this.ns,
110
+ findCommand,
111
+ {
112
+ ...this.options,
113
+ ...this.bsonOptions,
114
+ documentsReturnedIn: 'firstBatch',
115
+ session
116
+ },
117
+ undefined
118
+ );
120
119
  }
121
120
  }
122
121
 
@@ -1,4 +1,5 @@
1
1
  import type { Document, Long } from '../bson';
2
+ import { CursorResponse } from '../cmap/wire_protocol/responses';
2
3
  import { MongoRuntimeError } from '../error';
3
4
  import type { Server } from '../sdam/server';
4
5
  import type { ClientSession } from '../sessions';
@@ -19,6 +20,8 @@ export interface GetMoreOptions extends OperationOptions {
19
20
  maxTimeMS?: number;
20
21
  /** TODO(NODE-4413): Address bug with maxAwaitTimeMS not being passed in from the cursor correctly */
21
22
  maxAwaitTimeMS?: number;
23
+
24
+ useCursorResponse: boolean;
22
25
  }
23
26
 
24
27
  /**
@@ -96,7 +99,12 @@ export class GetMoreOperation extends AbstractOperation {
96
99
  ...this.options
97
100
  };
98
101
 
99
- return server.command(this.ns, getMoreCmd, commandOptions);
102
+ return await server.command(
103
+ this.ns,
104
+ getMoreCmd,
105
+ commandOptions,
106
+ this.options.useCursorResponse ? CursorResponse : undefined
107
+ );
100
108
  }
101
109
  }
102
110