mongodb 6.19.0 → 6.20.0-dev.20250920.sha.e8a91a91

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 (111) hide show
  1. package/lib/beta.d.ts +39 -13
  2. package/lib/bulk/common.js +2 -2
  3. package/lib/bulk/common.js.map +1 -1
  4. package/lib/change_stream.js +5 -1
  5. package/lib/change_stream.js.map +1 -1
  6. package/lib/cmap/auth/aws_temporary_credentials.js +10 -58
  7. package/lib/cmap/auth/aws_temporary_credentials.js.map +1 -1
  8. package/lib/cmap/auth/mongodb_aws.js +1 -4
  9. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  10. package/lib/cmap/connection.js +1 -3
  11. package/lib/cmap/connection.js.map +1 -1
  12. package/lib/cmap/handshake/client_metadata.js +22 -16
  13. package/lib/cmap/handshake/client_metadata.js.map +1 -1
  14. package/lib/cmap/wire_protocol/constants.js +5 -3
  15. package/lib/cmap/wire_protocol/constants.js.map +1 -1
  16. package/lib/collection.js +6 -5
  17. package/lib/collection.js.map +1 -1
  18. package/lib/connection_string.js +0 -5
  19. package/lib/connection_string.js.map +1 -1
  20. package/lib/cursor/change_stream_cursor.js +2 -3
  21. package/lib/cursor/change_stream_cursor.js.map +1 -1
  22. package/lib/db.js.map +1 -1
  23. package/lib/error.js +3 -0
  24. package/lib/error.js.map +1 -1
  25. package/lib/mongo_client.js +7 -2
  26. package/lib/mongo_client.js.map +1 -1
  27. package/lib/operations/aggregate.js +3 -8
  28. package/lib/operations/aggregate.js.map +1 -1
  29. package/lib/operations/client_bulk_write/client_bulk_write.js +2 -1
  30. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -1
  31. package/lib/operations/command.js +6 -0
  32. package/lib/operations/command.js.map +1 -1
  33. package/lib/operations/count.js +1 -1
  34. package/lib/operations/count.js.map +1 -1
  35. package/lib/operations/delete.js +13 -7
  36. package/lib/operations/delete.js.map +1 -1
  37. package/lib/operations/distinct.js +6 -1
  38. package/lib/operations/distinct.js.map +1 -1
  39. package/lib/operations/estimated_document_count.js +2 -1
  40. package/lib/operations/estimated_document_count.js.map +1 -1
  41. package/lib/operations/find.js +2 -1
  42. package/lib/operations/find.js.map +1 -1
  43. package/lib/operations/find_and_modify.js +6 -5
  44. package/lib/operations/find_and_modify.js.map +1 -1
  45. package/lib/operations/indexes.js +4 -3
  46. package/lib/operations/indexes.js.map +1 -1
  47. package/lib/operations/insert.js +10 -2
  48. package/lib/operations/insert.js.map +1 -1
  49. package/lib/operations/list_collections.js +2 -1
  50. package/lib/operations/list_collections.js.map +1 -1
  51. package/lib/operations/operation.js +2 -1
  52. package/lib/operations/operation.js.map +1 -1
  53. package/lib/operations/rename.js +1 -1
  54. package/lib/operations/rename.js.map +1 -1
  55. package/lib/operations/update.js +12 -11
  56. package/lib/operations/update.js.map +1 -1
  57. package/lib/read_preference.js.map +1 -1
  58. package/lib/sdam/server.js +1 -1
  59. package/lib/sdam/server.js.map +1 -1
  60. package/lib/sdam/server_selection.js +0 -6
  61. package/lib/sdam/server_selection.js.map +1 -1
  62. package/lib/sdam/topology.js +12 -9
  63. package/lib/sdam/topology.js.map +1 -1
  64. package/lib/sessions.js +0 -8
  65. package/lib/sessions.js.map +1 -1
  66. package/lib/utils.js +25 -26
  67. package/lib/utils.js.map +1 -1
  68. package/mongodb.d.ts +39 -13
  69. package/package.json +9 -9
  70. package/src/bulk/common.ts +2 -2
  71. package/src/change_stream.ts +5 -1
  72. package/src/cmap/auth/aws_temporary_credentials.ts +12 -70
  73. package/src/cmap/auth/mongodb_aws.ts +4 -11
  74. package/src/cmap/connection.ts +1 -6
  75. package/src/cmap/handshake/client_metadata.ts +36 -29
  76. package/src/cmap/wire_protocol/constants.ts +4 -2
  77. package/src/collection.ts +11 -5
  78. package/src/connection_string.ts +0 -11
  79. package/src/cursor/change_stream_cursor.ts +2 -3
  80. package/src/db.ts +4 -1
  81. package/src/error.ts +4 -0
  82. package/src/mongo_client.ts +18 -3
  83. package/src/operations/aggregate.ts +4 -10
  84. package/src/operations/client_bulk_write/client_bulk_write.ts +2 -1
  85. package/src/operations/command.ts +23 -2
  86. package/src/operations/count.ts +1 -1
  87. package/src/operations/create_collection.ts +1 -1
  88. package/src/operations/delete.ts +15 -8
  89. package/src/operations/distinct.ts +6 -1
  90. package/src/operations/drop.ts +1 -1
  91. package/src/operations/estimated_document_count.ts +2 -1
  92. package/src/operations/find.ts +2 -1
  93. package/src/operations/find_and_modify.ts +7 -6
  94. package/src/operations/indexes.ts +6 -3
  95. package/src/operations/insert.ts +10 -2
  96. package/src/operations/list_collections.ts +2 -1
  97. package/src/operations/list_databases.ts +1 -1
  98. package/src/operations/operation.ts +2 -1
  99. package/src/operations/profiling_level.ts +1 -1
  100. package/src/operations/remove_user.ts +1 -1
  101. package/src/operations/rename.ts +2 -2
  102. package/src/operations/set_profiling_level.ts +1 -1
  103. package/src/operations/stats.ts +1 -1
  104. package/src/operations/update.ts +13 -13
  105. package/src/operations/validate_collection.ts +1 -1
  106. package/src/read_preference.ts +3 -0
  107. package/src/sdam/server.ts +1 -1
  108. package/src/sdam/server_selection.ts +1 -12
  109. package/src/sdam/topology.ts +12 -9
  110. package/src/sessions.ts +0 -15
  111. package/src/utils.ts +26 -30
@@ -356,6 +356,8 @@ export class DropIndexOperation extends CommandOperation<Document> {
356
356
  export type ListIndexesOptions = AbstractCursorOptions & {
357
357
  /** @internal */
358
358
  omitMaxTimeMS?: boolean;
359
+ /** @internal */
360
+ rawData?: boolean;
359
361
  };
360
362
 
361
363
  /** @internal */
@@ -409,7 +411,8 @@ export class ListIndexesOperation extends CommandOperation<CursorResponse> {
409
411
  defineAspects(ListIndexesOperation, [
410
412
  Aspect.READ_OPERATION,
411
413
  Aspect.RETRYABLE,
412
- Aspect.CURSOR_CREATING
414
+ Aspect.CURSOR_CREATING,
415
+ Aspect.SUPPORTS_RAW_DATA
413
416
  ]);
414
- defineAspects(CreateIndexesOperation, [Aspect.WRITE_OPERATION]);
415
- defineAspects(DropIndexOperation, [Aspect.WRITE_OPERATION]);
417
+ defineAspects(CreateIndexesOperation, [Aspect.WRITE_OPERATION, Aspect.SUPPORTS_RAW_DATA]);
418
+ defineAspects(DropIndexOperation, [Aspect.WRITE_OPERATION, Aspect.SUPPORTS_RAW_DATA]);
@@ -96,5 +96,13 @@ export interface InsertManyResult<TSchema = Document> {
96
96
  insertedIds: { [key: number]: InferIdType<TSchema> };
97
97
  }
98
98
 
99
- defineAspects(InsertOperation, [Aspect.RETRYABLE, Aspect.WRITE_OPERATION]);
100
- defineAspects(InsertOneOperation, [Aspect.RETRYABLE, Aspect.WRITE_OPERATION]);
99
+ defineAspects(InsertOperation, [
100
+ Aspect.RETRYABLE,
101
+ Aspect.WRITE_OPERATION,
102
+ Aspect.SUPPORTS_RAW_DATA
103
+ ]);
104
+ defineAspects(InsertOneOperation, [
105
+ Aspect.RETRYABLE,
106
+ Aspect.WRITE_OPERATION,
107
+ Aspect.SUPPORTS_RAW_DATA
108
+ ]);
@@ -103,5 +103,6 @@ export interface CollectionInfo extends Document {
103
103
  defineAspects(ListCollectionsOperation, [
104
104
  Aspect.READ_OPERATION,
105
105
  Aspect.RETRYABLE,
106
- Aspect.CURSOR_CREATING
106
+ Aspect.CURSOR_CREATING,
107
+ Aspect.SUPPORTS_RAW_DATA
107
108
  ]);
@@ -16,7 +16,7 @@ export interface ListDatabasesResult {
16
16
  }
17
17
 
18
18
  /** @public */
19
- export interface ListDatabasesOptions extends CommandOperationOptions {
19
+ export interface ListDatabasesOptions extends Omit<CommandOperationOptions, 'rawData'> {
20
20
  /** A query predicate that determines which databases are listed */
21
21
  filter?: Document;
22
22
  /** A flag to indicate whether the command should return just the database names, or return both database names and size information */
@@ -16,7 +16,8 @@ export const Aspect = {
16
16
  SKIP_COLLATION: Symbol('SKIP_COLLATION'),
17
17
  CURSOR_CREATING: Symbol('CURSOR_CREATING'),
18
18
  MUST_SELECT_SAME_SERVER: Symbol('MUST_SELECT_SAME_SERVER'),
19
- COMMAND_BATCHING: Symbol('COMMAND_BATCHING')
19
+ COMMAND_BATCHING: Symbol('COMMAND_BATCHING'),
20
+ SUPPORTS_RAW_DATA: Symbol('SUPPORTS_RAW_DATA')
20
21
  } as const;
21
22
 
22
23
  /** @public */
@@ -6,7 +6,7 @@ import { MongoUnexpectedServerResponseError } from '../error';
6
6
  import { CommandOperation, type CommandOperationOptions } from './command';
7
7
 
8
8
  /** @public */
9
- export type ProfilingLevelOptions = CommandOperationOptions;
9
+ export type ProfilingLevelOptions = Omit<CommandOperationOptions, 'rawData'>;
10
10
 
11
11
  class ProfilingLevelResponse extends MongoDBResponse {
12
12
  get was() {
@@ -6,7 +6,7 @@ import { CommandOperation, type CommandOperationOptions } from './command';
6
6
  import { Aspect, defineAspects } from './operation';
7
7
 
8
8
  /** @public */
9
- export type RemoveUserOptions = CommandOperationOptions;
9
+ export type RemoveUserOptions = Omit<CommandOperationOptions, 'rawData'>;
10
10
 
11
11
  /** @internal */
12
12
  export class RemoveUserOperation extends CommandOperation<boolean> {
@@ -8,7 +8,7 @@ import { CommandOperation, type CommandOperationOptions } from './command';
8
8
  import { Aspect, defineAspects } from './operation';
9
9
 
10
10
  /** @public */
11
- export interface RenameOptions extends CommandOperationOptions {
11
+ export interface RenameOptions extends Omit<CommandOperationOptions, 'rawData'> {
12
12
  /** Drop the target name collection if it previously exists. */
13
13
  dropTarget?: boolean;
14
14
  /** Unclear */
@@ -48,7 +48,7 @@ export class RenameOperation extends CommandOperation<Document> {
48
48
  }
49
49
 
50
50
  override handleOk(_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
51
- return new Collection(this.collection.s.db, this.newName, this.collection.s.options);
51
+ return new Collection(this.collection.db, this.newName, this.collection.s.options);
52
52
  }
53
53
  }
54
54
 
@@ -19,7 +19,7 @@ export const ProfilingLevel = Object.freeze({
19
19
  export type ProfilingLevel = (typeof ProfilingLevel)[keyof typeof ProfilingLevel];
20
20
 
21
21
  /** @public */
22
- export type SetProfilingLevelOptions = CommandOperationOptions;
22
+ export type SetProfilingLevelOptions = Omit<CommandOperationOptions, 'rawData'>;
23
23
 
24
24
  /** @internal */
25
25
  export class SetProfilingLevelOperation extends CommandOperation<ProfilingLevel> {
@@ -6,7 +6,7 @@ import { CommandOperation, type CommandOperationOptions } from './command';
6
6
  import { Aspect, defineAspects } from './operation';
7
7
 
8
8
  /** @public */
9
- export interface DbStatsOptions extends CommandOperationOptions {
9
+ export interface DbStatsOptions extends Omit<CommandOperationOptions, 'rawData'> {
10
10
  /** Divide the returned sizes by scale value. */
11
11
  scale?: number;
12
12
  }
@@ -1,7 +1,7 @@
1
1
  import type { Document } from '../bson';
2
2
  import { type Connection } from '../cmap/connection';
3
3
  import { MongoDBResponse } from '../cmap/wire_protocol/responses';
4
- import { MongoCompatibilityError, MongoInvalidArgumentError, MongoServerError } from '../error';
4
+ import { MongoInvalidArgumentError, MongoServerError } from '../error';
5
5
  import type { InferIdType } from '../mongo_types';
6
6
  import type { ClientSession } from '../sessions';
7
7
  import { formatSort, type Sort, type SortForCmd } from '../sort';
@@ -121,14 +121,6 @@ export class UpdateOperation extends CommandOperation<Document> {
121
121
  command.comment = options.comment;
122
122
  }
123
123
 
124
- const unacknowledgedWrite = this.writeConcern?.w === 0;
125
- if (unacknowledgedWrite) {
126
- if (this.statements.find((o: Document) => o.hint)) {
127
- // TODO(NODE-3541): fix error for hint with unacknowledged writes
128
- throw new MongoCompatibilityError(`hint is not supported with unacknowledged writes`);
129
- }
130
- }
131
-
132
124
  return command;
133
125
  }
134
126
  }
@@ -299,20 +291,28 @@ export function makeUpdateStatement(
299
291
  return op;
300
292
  }
301
293
 
302
- defineAspects(UpdateOperation, [Aspect.RETRYABLE, Aspect.WRITE_OPERATION, Aspect.SKIP_COLLATION]);
294
+ defineAspects(UpdateOperation, [
295
+ Aspect.RETRYABLE,
296
+ Aspect.WRITE_OPERATION,
297
+ Aspect.SKIP_COLLATION,
298
+ Aspect.SUPPORTS_RAW_DATA
299
+ ]);
303
300
  defineAspects(UpdateOneOperation, [
304
301
  Aspect.RETRYABLE,
305
302
  Aspect.WRITE_OPERATION,
306
303
  Aspect.EXPLAINABLE,
307
- Aspect.SKIP_COLLATION
304
+ Aspect.SKIP_COLLATION,
305
+ Aspect.SUPPORTS_RAW_DATA
308
306
  ]);
309
307
  defineAspects(UpdateManyOperation, [
310
308
  Aspect.WRITE_OPERATION,
311
309
  Aspect.EXPLAINABLE,
312
- Aspect.SKIP_COLLATION
310
+ Aspect.SKIP_COLLATION,
311
+ Aspect.SUPPORTS_RAW_DATA
313
312
  ]);
314
313
  defineAspects(ReplaceOneOperation, [
315
314
  Aspect.RETRYABLE,
316
315
  Aspect.WRITE_OPERATION,
317
- Aspect.SKIP_COLLATION
316
+ Aspect.SKIP_COLLATION,
317
+ Aspect.SUPPORTS_RAW_DATA
318
318
  ]);
@@ -7,7 +7,7 @@ import type { ClientSession } from '../sessions';
7
7
  import { CommandOperation, type CommandOperationOptions } from './command';
8
8
 
9
9
  /** @public */
10
- export interface ValidateCollectionOptions extends CommandOperationOptions {
10
+ export interface ValidateCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
11
11
  /** Validates a collection in the background, without interrupting read or write traffic (only in MongoDB 4.4+) */
12
12
  background?: boolean;
13
13
  }
@@ -63,6 +63,9 @@ export class ReadPreference {
63
63
  tags?: TagSet[];
64
64
  hedge?: HedgeOptions;
65
65
  maxStalenessSeconds?: number;
66
+ /**
67
+ * @deprecated This will be removed as dead code in the next major version.
68
+ */
66
69
  minWireVersion?: number;
67
70
 
68
71
  public static PRIMARY = ReadPreferenceMode.primary;
@@ -414,7 +414,7 @@ export class Server extends TypedEventEmitter<ServerEvents> {
414
414
  } else {
415
415
  if (isSDAMUnrecoverableError(error)) {
416
416
  if (shouldHandleStateChangeError(this, error)) {
417
- const shouldClearPool = maxWireVersion(this) <= 7 || isNodeShuttingDownError(error);
417
+ const shouldClearPool = isNodeShuttingDownError(error);
418
418
  if (this.loadBalanced && connection && shouldClearPool) {
419
419
  this.pool.clear({ serviceId: connection.serviceId });
420
420
  }
@@ -1,4 +1,4 @@
1
- import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
1
+ import { MongoInvalidArgumentError } from '../error';
2
2
  import { ReadPreference } from '../read_preference';
3
3
  import { ServerType, TopologyType } from './common';
4
4
  import type { ServerDescription, TagSet } from './server_description';
@@ -273,17 +273,6 @@ export function readPreferenceServerSelector(readPreference: ReadPreference): Se
273
273
  servers: ServerDescription[],
274
274
  deprioritized: ServerDescription[] = []
275
275
  ): ServerDescription[] {
276
- const commonWireVersion = topologyDescription.commonWireVersion;
277
- if (
278
- commonWireVersion &&
279
- readPreference.minWireVersion &&
280
- readPreference.minWireVersion > commonWireVersion
281
- ) {
282
- throw new MongoCompatibilityError(
283
- `Minimum wire version '${readPreference.minWireVersion}' required, but found '${commonWireVersion}'`
284
- );
285
- }
286
-
287
276
  if (topologyDescription.type === TopologyType.LoadBalanced) {
288
277
  return servers.filter(loadBalancerFilter);
289
278
  }
@@ -1104,7 +1104,10 @@ function isStaleServerDescription(
1104
1104
  );
1105
1105
  }
1106
1106
 
1107
- /** @public */
1107
+ /**
1108
+ * @public
1109
+ * @deprecated This class will be removed as dead code in the next major version.
1110
+ */
1108
1111
  export class ServerCapabilities {
1109
1112
  maxWireVersion: number;
1110
1113
  minWireVersion: number;
@@ -1115,26 +1118,26 @@ export class ServerCapabilities {
1115
1118
  }
1116
1119
 
1117
1120
  get hasAggregationCursor(): boolean {
1118
- return this.maxWireVersion >= 1;
1121
+ return true;
1119
1122
  }
1120
1123
 
1121
1124
  get hasWriteCommands(): boolean {
1122
- return this.maxWireVersion >= 2;
1125
+ return true;
1123
1126
  }
1124
1127
  get hasTextSearch(): boolean {
1125
- return this.minWireVersion >= 0;
1128
+ return true;
1126
1129
  }
1127
1130
 
1128
1131
  get hasAuthCommands(): boolean {
1129
- return this.maxWireVersion >= 1;
1132
+ return true;
1130
1133
  }
1131
1134
 
1132
1135
  get hasListCollectionsCommand(): boolean {
1133
- return this.maxWireVersion >= 3;
1136
+ return true;
1134
1137
  }
1135
1138
 
1136
1139
  get hasListIndexesCommand(): boolean {
1137
- return this.maxWireVersion >= 3;
1140
+ return true;
1138
1141
  }
1139
1142
 
1140
1143
  get supportsSnapshotReads(): boolean {
@@ -1142,10 +1145,10 @@ export class ServerCapabilities {
1142
1145
  }
1143
1146
 
1144
1147
  get commandsTakeWriteConcern(): boolean {
1145
- return this.maxWireVersion >= 5;
1148
+ return true;
1146
1149
  }
1147
1150
 
1148
1151
  get commandsTakeCollation(): boolean {
1149
- return this.maxWireVersion >= 5;
1152
+ return true;
1150
1153
  }
1151
1154
  }
package/src/sessions.ts CHANGED
@@ -2,7 +2,6 @@ import { Binary, type Document, Long, type Timestamp } from './bson';
2
2
  import type { CommandOptions, Connection } from './cmap/connection';
3
3
  import { ConnectionPoolMetrics } from './cmap/metrics';
4
4
  import { type MongoDBResponse } from './cmap/wire_protocol/responses';
5
- import { isSharded } from './cmap/wire_protocol/shared';
6
5
  import { PINNED, UNPINNED } from './constants';
7
6
  import type { AbstractCursor } from './cursor/abstract_cursor';
8
7
  import {
@@ -42,7 +41,6 @@ import {
42
41
  commandSupportsReadConcern,
43
42
  isPromiseLike,
44
43
  List,
45
- maxWireVersion,
46
44
  MongoDBNamespace,
47
45
  noop,
48
46
  now,
@@ -51,8 +49,6 @@ import {
51
49
  } from './utils';
52
50
  import { WriteConcern, type WriteConcernOptions, type WriteConcernSettings } from './write_concern';
53
51
 
54
- const minWireVersionForShardedTransactions = 8;
55
-
56
52
  /** @public */
57
53
  export interface ClientSessionOptions {
58
54
  /** Whether causal consistency should be enabled on this session */
@@ -405,17 +401,6 @@ export class ClientSession
405
401
  this.unpin();
406
402
  }
407
403
 
408
- const topologyMaxWireVersion = maxWireVersion(this.client.topology);
409
- if (
410
- isSharded(this.client.topology) &&
411
- topologyMaxWireVersion != null &&
412
- topologyMaxWireVersion < minWireVersionForShardedTransactions
413
- ) {
414
- throw new MongoCompatibilityError(
415
- 'Transactions are not supported on sharded clusters in MongoDB < 4.2.'
416
- );
417
- }
418
-
419
404
  this.commitAttempted = false;
420
405
  // increment txnNumber
421
406
  this.incrementTransactionNumber();
package/src/utils.ts CHANGED
@@ -19,7 +19,6 @@ import type { Db } from './db';
19
19
  import {
20
20
  type AnyError,
21
21
  MongoAPIError,
22
- MongoCompatibilityError,
23
22
  MongoInvalidArgumentError,
24
23
  MongoNetworkTimeoutError,
25
24
  MongoNotConnectedError,
@@ -206,18 +205,9 @@ export function isPromiseLike<T = unknown>(value?: unknown): value is PromiseLik
206
205
  * @param target - target of command
207
206
  * @param options - options containing collation settings
208
207
  */
209
- export function decorateWithCollation(
210
- command: Document,
211
- target: MongoClient | Db | Collection,
212
- options: AnyOptions
213
- ): void {
214
- const capabilities = getTopology(target).capabilities;
208
+ export function decorateWithCollation(command: Document, options: AnyOptions): void {
215
209
  if (options.collation && typeof options.collation === 'object') {
216
- if (capabilities && capabilities.commandsTakeCollation) {
217
- command.collation = options.collation;
218
- } else {
219
- throw new MongoCompatibilityError(`Current topology does not support collation`);
220
- }
210
+ command.collation = options.collation;
221
211
  }
222
212
  }
223
213
 
@@ -359,34 +349,40 @@ export function uuidV4(): Buffer {
359
349
  * A helper function for determining `maxWireVersion` between legacy and new topology instances
360
350
  * @internal
361
351
  */
362
- export function maxWireVersion(topologyOrServer?: Connection | Topology | Server): number {
363
- if (topologyOrServer) {
364
- if (topologyOrServer.loadBalanced || topologyOrServer.serverApi?.version) {
365
- // Since we do not have a monitor in the load balanced mode,
366
- // we assume the load-balanced server is always pointed at the latest mongodb version.
367
- // There is a risk that for on-prem deployments
368
- // that don't upgrade immediately that this could alert to the
369
- // application that a feature is available that is actually not.
370
- // We also return the max supported wire version for serverAPI.
352
+ export function maxWireVersion(handshakeAware?: Connection | Topology | Server): number {
353
+ if (handshakeAware) {
354
+ if (handshakeAware.hello) {
355
+ return handshakeAware.hello.maxWireVersion;
356
+ }
357
+
358
+ if (handshakeAware.serverApi?.version) {
359
+ // We return the max supported wire version for serverAPI.
371
360
  return MAX_SUPPORTED_WIRE_VERSION;
372
361
  }
373
- if (topologyOrServer.hello) {
374
- return topologyOrServer.hello.maxWireVersion;
362
+ // This is the fallback case for load balanced mode. If we are building commands the
363
+ // object being checked will be a connection, and we will have a hello response on
364
+ // it. For other cases, such as retryable writes, the object will be a server or
365
+ // topology, and there will be no hello response on those objects, so we return
366
+ // the max wire version so we support retryability. Once we have a min supported
367
+ // wire version of 9, then the needsRetryableWriteLabel() check can remove the
368
+ // usage of passing the wire version into it.
369
+ if (handshakeAware.loadBalanced) {
370
+ return MAX_SUPPORTED_WIRE_VERSION;
375
371
  }
376
372
 
377
- if ('lastHello' in topologyOrServer && typeof topologyOrServer.lastHello === 'function') {
378
- const lastHello = topologyOrServer.lastHello();
373
+ if ('lastHello' in handshakeAware && typeof handshakeAware.lastHello === 'function') {
374
+ const lastHello = handshakeAware.lastHello();
379
375
  if (lastHello) {
380
376
  return lastHello.maxWireVersion;
381
377
  }
382
378
  }
383
379
 
384
380
  if (
385
- topologyOrServer.description &&
386
- 'maxWireVersion' in topologyOrServer.description &&
387
- topologyOrServer.description.maxWireVersion != null
381
+ handshakeAware.description &&
382
+ 'maxWireVersion' in handshakeAware.description &&
383
+ handshakeAware.description.maxWireVersion != null
388
384
  ) {
389
- return topologyOrServer.description.maxWireVersion;
385
+ return handshakeAware.description.maxWireVersion;
390
386
  }
391
387
  }
392
388
 
@@ -1362,7 +1358,7 @@ export function maybeAddIdToDocuments(
1362
1358
  options: { forceServerObjectId?: boolean }
1363
1359
  ): Document {
1364
1360
  const forceServerObjectId =
1365
- options.forceServerObjectId ?? collection.s.db.options?.forceServerObjectId ?? false;
1361
+ options.forceServerObjectId ?? collection.db.options?.forceServerObjectId ?? false;
1366
1362
 
1367
1363
  // no need to modify the docs if server sets the ObjectId
1368
1364
  if (forceServerObjectId) {