mongodb 6.19.0 → 6.20.0-dev.20250919.sha.b7c67507

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
@@ -11,9 +11,7 @@ import { type AuthContext, AuthProvider } from './auth_provider';
11
11
  import {
12
12
  type AWSCredentialProvider,
13
13
  AWSSDKCredentialProvider,
14
- type AWSTempCredentials,
15
- AWSTemporaryCredentialProvider,
16
- LegacyAWSTemporaryCredentialProvider
14
+ type AWSTempCredentials
17
15
  } from './aws_temporary_credentials';
18
16
  import { MongoCredentials } from './mongo_credentials';
19
17
  import { AuthMechanism } from './providers';
@@ -34,16 +32,11 @@ interface AWSSaslContinuePayload {
34
32
  }
35
33
 
36
34
  export class MongoDBAWS extends AuthProvider {
37
- private credentialFetcher: AWSTemporaryCredentialProvider;
38
- private credentialProvider?: AWSCredentialProvider;
35
+ private credentialFetcher: AWSSDKCredentialProvider;
39
36
 
40
37
  constructor(credentialProvider?: AWSCredentialProvider) {
41
38
  super();
42
-
43
- this.credentialProvider = credentialProvider;
44
- this.credentialFetcher = AWSTemporaryCredentialProvider.isAWSSDKInstalled
45
- ? new AWSSDKCredentialProvider(credentialProvider)
46
- : new LegacyAWSTemporaryCredentialProvider();
39
+ this.credentialFetcher = new AWSSDKCredentialProvider(credentialProvider);
47
40
  }
48
41
 
49
42
  override async auth(authContext: AuthContext): Promise<void> {
@@ -162,7 +155,7 @@ export class MongoDBAWS extends AuthProvider {
162
155
 
163
156
  async function makeTempCredentials(
164
157
  credentials: MongoCredentials,
165
- awsCredentialFetcher: AWSTemporaryCredentialProvider
158
+ awsCredentialFetcher: AWSSDKCredentialProvider
166
159
  ): Promise<MongoCredentials> {
167
160
  function makeMongoCredentialsFromAWSTemp(creds: AWSTempCredentials) {
168
161
  // The AWS session token (creds.Token) may or may not be set.
@@ -284,6 +284,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
284
284
  private get supportsOpMsg(): boolean {
285
285
  return (
286
286
  this.description != null &&
287
+ // TODO(NODE-6672,NODE-6287): This guard is primarily for maxWireVersion = 0
287
288
  maxWireVersion(this) >= 6 &&
288
289
  !this.description.__nodejs_mock_server__
289
290
  );
@@ -880,12 +881,6 @@ export class CryptoConnection extends Connection {
880
881
  return await super.command<T>(ns, cmd, options, responseType);
881
882
  }
882
883
 
883
- if (serverWireVersion < 8) {
884
- throw new MongoCompatibilityError(
885
- 'Auto-encryption requires a minimum MongoDB version of 4.2'
886
- );
887
- }
888
-
889
884
  // Save sort or indexKeys based on the command being run
890
885
  // the encrypt API serializes our JS objects to BSON to pass to the native code layer
891
886
  // and then deserializes the encrypted result, the protocol level components
@@ -2,13 +2,30 @@ import * as os from 'os';
2
2
  import * as process from 'process';
3
3
 
4
4
  import { BSON, type Document, Int32 } from '../../bson';
5
- import { MongoInvalidArgumentError, MongoRuntimeError } from '../../error';
6
- import type { MongoOptions } from '../../mongo_client';
5
+ import { MongoInvalidArgumentError } from '../../error';
6
+ import type { DriverInfo, MongoOptions } from '../../mongo_client';
7
7
  import { fileIsAccessible } from '../../utils';
8
8
 
9
9
  // eslint-disable-next-line @typescript-eslint/no-require-imports
10
10
  const NODE_DRIVER_VERSION = require('../../../package.json').version;
11
11
 
12
+ /** @internal */
13
+ export function isDriverInfoEqual(info1: DriverInfo, info2: DriverInfo): boolean {
14
+ /** for equality comparison, we consider "" as unset */
15
+ const nonEmptyCmp = (s1: string | undefined, s2: string | undefined): boolean => {
16
+ s1 ||= undefined;
17
+ s2 ||= undefined;
18
+
19
+ return s1 === s2;
20
+ };
21
+
22
+ return (
23
+ nonEmptyCmp(info1.name, info2.name) &&
24
+ nonEmptyCmp(info1.platform, info2.platform) &&
25
+ nonEmptyCmp(info1.version, info2.version)
26
+ );
27
+ }
28
+
12
29
  /**
13
30
  * @public
14
31
  * @deprecated This interface will be made internal in the next major release.
@@ -90,10 +107,7 @@ export class LimitedSizeDocument {
90
107
  }
91
108
  }
92
109
 
93
- type MakeClientMetadataOptions = Pick<
94
- MongoOptions,
95
- 'appName' | 'driverInfo' | 'additionalDriverInfo'
96
- >;
110
+ type MakeClientMetadataOptions = Pick<MongoOptions, 'appName'>;
97
111
  /**
98
112
  * From the specs:
99
113
  * Implementors SHOULD cumulatively update fields in the following order until the document is under the size limit:
@@ -102,34 +116,28 @@ type MakeClientMetadataOptions = Pick<
102
116
  * 3. Omit the `env` document entirely.
103
117
  * 4. Truncate `platform`. -- special we do not truncate this field
104
118
  */
105
- export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMetadata {
119
+ export function makeClientMetadata(
120
+ driverInfoList: DriverInfo[],
121
+ { appName = '' }: MakeClientMetadataOptions
122
+ ): ClientMetadata {
106
123
  const metadataDocument = new LimitedSizeDocument(512);
107
124
 
108
- const { appName = '' } = options;
109
125
  // Add app name first, it must be sent
110
126
  if (appName.length > 0) {
111
127
  const name =
112
128
  Buffer.byteLength(appName, 'utf8') <= 128
113
- ? options.appName
129
+ ? appName
114
130
  : Buffer.from(appName, 'utf8').subarray(0, 128).toString('utf8');
115
131
  metadataDocument.ifItFitsItSits('application', { name });
116
132
  }
117
133
 
118
- const { name = '', version = '', platform = '' } = options.driverInfo;
119
-
120
134
  const driverInfo = {
121
- name: name.length > 0 ? `nodejs|${name}` : 'nodejs',
122
- version: version.length > 0 ? `${NODE_DRIVER_VERSION}|${version}` : NODE_DRIVER_VERSION
135
+ name: 'nodejs',
136
+ version: NODE_DRIVER_VERSION
123
137
  };
124
138
 
125
- if (options.additionalDriverInfo == null) {
126
- throw new MongoRuntimeError(
127
- 'Client options `additionalDriverInfo` must always default to an empty array'
128
- );
129
- }
130
-
131
139
  // This is where we handle additional driver info added after client construction.
132
- for (const { name: n = '', version: v = '' } of options.additionalDriverInfo) {
140
+ for (const { name: n = '', version: v = '' } of driverInfoList) {
133
141
  if (n.length > 0) {
134
142
  driverInfo.name = `${driverInfo.name}|${n}`;
135
143
  }
@@ -145,13 +153,10 @@ export function makeClientMetadata(options: MakeClientMetadataOptions): ClientMe
145
153
  }
146
154
 
147
155
  let runtimeInfo = getRuntimeInfo();
148
- if (platform.length > 0) {
149
- runtimeInfo = `${runtimeInfo}|${platform}`;
150
- }
151
-
152
- for (const { platform: p = '' } of options.additionalDriverInfo) {
153
- if (p.length > 0) {
154
- runtimeInfo = `${runtimeInfo}|${p}`;
156
+ // This is where we handle additional driver info added after client construction.
157
+ for (const { platform = '' } of driverInfoList) {
158
+ if (platform.length > 0) {
159
+ runtimeInfo = `${runtimeInfo}|${platform}`;
155
160
  }
156
161
  }
157
162
 
@@ -210,7 +215,9 @@ async function getContainerMetadata() {
210
215
  * Re-add each metadata value.
211
216
  * Attempt to add new env container metadata, but keep old data if it does not fit.
212
217
  */
213
- export async function addContainerMetadata(originalMetadata: ClientMetadata) {
218
+ export async function addContainerMetadata(
219
+ originalMetadata: ClientMetadata
220
+ ): Promise<ClientMetadata> {
214
221
  const containerMetadata = await getContainerMetadata();
215
222
  if (Object.keys(containerMetadata).length === 0) return originalMetadata;
216
223
 
@@ -233,7 +240,7 @@ export async function addContainerMetadata(originalMetadata: ClientMetadata) {
233
240
  extendedMetadata.ifItFitsItSits('env', extendedEnvMetadata);
234
241
  }
235
242
 
236
- return extendedMetadata.toObject();
243
+ return extendedMetadata.toObject() as ClientMetadata;
237
244
  }
238
245
 
239
246
  /**
@@ -1,9 +1,11 @@
1
1
  export const MIN_SUPPORTED_SERVER_VERSION = '4.2';
2
- export const MAX_SUPPORTED_SERVER_VERSION = '8.0';
2
+ export const MAX_SUPPORTED_SERVER_VERSION = '8.2';
3
3
  export const MIN_SUPPORTED_WIRE_VERSION = 8;
4
- export const MAX_SUPPORTED_WIRE_VERSION = 25;
4
+ export const MAX_SUPPORTED_WIRE_VERSION = 27;
5
5
  export const MIN_SUPPORTED_QE_WIRE_VERSION = 21;
6
6
  export const MIN_SUPPORTED_QE_SERVER_VERSION = '7.0';
7
+ export const MIN_SUPPORTED_RAW_DATA_WIRE_VERSION = 27;
8
+ export const MIN_SUPPORTED_RAW_DATA_SERVER_VERSION = '8.2';
7
9
  export const OP_REPLY = 1;
8
10
  export const OP_UPDATE = 2001;
9
11
  export const OP_INSERT = 2002;
package/src/collection.ts CHANGED
@@ -172,11 +172,17 @@ export class Collection<TSchema extends Document = Document> {
172
172
  /** @internal */
173
173
  client: MongoClient;
174
174
 
175
+ /**
176
+ * Get the database object for the collection.
177
+ */
178
+ readonly db: Db;
179
+
175
180
  /**
176
181
  * Create a new Collection instance
177
182
  * @internal
178
183
  */
179
184
  constructor(db: Db, name: string, options?: CollectionOptions) {
185
+ this.db = db;
180
186
  // Internal state
181
187
  this.s = {
182
188
  db,
@@ -228,7 +234,7 @@ export class Collection<TSchema extends Document = Document> {
228
234
  */
229
235
  get readConcern(): ReadConcern | undefined {
230
236
  if (this.s.readConcern == null) {
231
- return this.s.db.readConcern;
237
+ return this.db.readConcern;
232
238
  }
233
239
  return this.s.readConcern;
234
240
  }
@@ -239,7 +245,7 @@ export class Collection<TSchema extends Document = Document> {
239
245
  */
240
246
  get readPreference(): ReadPreference | undefined {
241
247
  if (this.s.readPreference == null) {
242
- return this.s.db.readPreference;
248
+ return this.db.readPreference;
243
249
  }
244
250
 
245
251
  return this.s.readPreference;
@@ -255,7 +261,7 @@ export class Collection<TSchema extends Document = Document> {
255
261
  */
256
262
  get writeConcern(): WriteConcern | undefined {
257
263
  if (this.s.writeConcern == null) {
258
- return this.s.db.writeConcern;
264
+ return this.db.writeConcern;
259
265
  }
260
266
  return this.s.writeConcern;
261
267
  }
@@ -509,7 +515,7 @@ export class Collection<TSchema extends Document = Document> {
509
515
  * @param options - Optional settings for the command
510
516
  */
511
517
  async drop(options?: DropCollectionOptions): Promise<boolean> {
512
- return await this.s.db.dropCollection(this.collectionName, options);
518
+ return await this.db.dropCollection(this.collectionName, options);
513
519
  }
514
520
 
515
521
  /**
@@ -578,7 +584,7 @@ export class Collection<TSchema extends Document = Document> {
578
584
  */
579
585
  async options(options?: OperationOptions): Promise<Document> {
580
586
  options = resolveOptions(this, options);
581
- const [collection] = await this.s.db
587
+ const [collection] = await this.db
582
588
  .listCollections({ name: this.collectionName }, { ...options, nameOnly: false })
583
589
  .toArray();
584
590
 
@@ -5,7 +5,6 @@ import { URLSearchParams } from 'url';
5
5
  import type { Document } from './bson';
6
6
  import { MongoCredentials } from './cmap/auth/mongo_credentials';
7
7
  import { AUTH_MECHS_AUTH_SRC_EXTERNAL, AuthMechanism } from './cmap/auth/providers';
8
- import { addContainerMetadata, makeClientMetadata } from './cmap/handshake/client_metadata';
9
8
  import { Compressor, type CompressorName } from './cmap/wire_protocol/compression';
10
9
  import { Encrypter } from './encrypter';
11
10
  import {
@@ -535,16 +534,6 @@ export function parseOptions(
535
534
  }
536
535
  );
537
536
 
538
- // Set the default for the additional driver info.
539
- mongoOptions.additionalDriverInfo = [];
540
-
541
- mongoOptions.metadata = makeClientMetadata(mongoOptions);
542
-
543
- mongoOptions.extendedMetadata = addContainerMetadata(mongoOptions.metadata).then(
544
- undefined,
545
- squashError
546
- ); // rejections will be handled later
547
-
548
537
  return mongoOptions;
549
538
  }
550
539
 
@@ -93,7 +93,7 @@ export class ChangeStreamCursor<
93
93
  } else {
94
94
  options.resumeAfter = this.resumeToken;
95
95
  }
96
- } else if (this.startAtOperationTime != null && maxWireVersion(this.server) >= 7) {
96
+ } else if (this.startAtOperationTime != null) {
97
97
  options.startAtOperationTime = this.startAtOperationTime;
98
98
  }
99
99
 
@@ -145,8 +145,7 @@ export class ChangeStreamCursor<
145
145
  if (
146
146
  this.startAtOperationTime == null &&
147
147
  this.changeStreamCursorOptions.resumeAfter == null &&
148
- this.changeStreamCursorOptions.startAfter == null &&
149
- this.maxWireVersion >= 7
148
+ this.changeStreamCursorOptions.startAfter == null
150
149
  ) {
151
150
  this.startAtOperationTime = response.operationTime;
152
151
  }
package/src/db.ts CHANGED
@@ -126,7 +126,10 @@ export class Db {
126
126
  /** @internal */
127
127
  s: DbPrivate;
128
128
 
129
- /** @internal */
129
+ /**
130
+ * Gets the MongoClient associated with the Db.
131
+ * @public
132
+ */
130
133
  readonly client: MongoClient;
131
134
 
132
135
  public static SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION;
package/src/error.ts CHANGED
@@ -1551,6 +1551,10 @@ export function isResumableError(error?: Error, wireVersion?: number): boolean {
1551
1551
  return true;
1552
1552
  }
1553
1553
 
1554
+ if (error instanceof MongoServerSelectionError) {
1555
+ return true;
1556
+ }
1557
+
1554
1558
  if (wireVersion != null && wireVersion >= 9) {
1555
1559
  // DRIVERS-1308: For 4.4 drivers running against 4.4 servers, drivers will add a special case to treat the CursorNotFound error code as resumable
1556
1560
  if (error.code === MONGODB_ERROR_CODES.CursorNotFound) {
@@ -18,6 +18,7 @@ import type { Connection } from './cmap/connection';
18
18
  import {
19
19
  addContainerMetadata,
20
20
  type ClientMetadata,
21
+ isDriverInfoEqual,
21
22
  makeClientMetadata
22
23
  } from './cmap/handshake/client_metadata';
23
24
  import type { CompressorName } from './cmap/wire_protocol/compression';
@@ -282,7 +283,10 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
282
283
  * If an internal MongoClient is created, it is configured with the same options as the parent MongoClient except minPoolSize is set to 0 and AutoEncryptionOptions is omitted.
283
284
  */
284
285
  autoEncryption?: AutoEncryptionOptions;
285
- /** Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver */
286
+ /**
287
+ * Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver
288
+ /* @deprecated - Will be made internal in a future major release.
289
+ */
286
290
  driverInfo?: DriverInfo;
287
291
  /** Configures a Socks5 proxy host used for creating TCP connections. */
288
292
  proxyHost?: string;
@@ -430,12 +434,16 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
430
434
  | 'extendedMetadata'
431
435
  >;
432
436
 
437
+ private driverInfoList: DriverInfo[] = [];
438
+
433
439
  constructor(url: string, options?: MongoClientOptions) {
434
440
  super();
435
441
  this.on('error', noop);
436
442
 
437
443
  this.options = parseOptions(url, this, options);
438
444
 
445
+ this.appendMetadata(this.options.driverInfo);
446
+
439
447
  const shouldSetLogger = Object.values(this.options.mongoLoggerOptions.componentSeverities).some(
440
448
  value => value !== SeverityLevel.OFF
441
449
  );
@@ -492,8 +500,13 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
492
500
  * @param driverInfo - Information about the application or library.
493
501
  */
494
502
  appendMetadata(driverInfo: DriverInfo) {
495
- this.options.additionalDriverInfo.push(driverInfo);
496
- this.options.metadata = makeClientMetadata(this.options);
503
+ const isDuplicateDriverInfo = this.driverInfoList.some(info =>
504
+ isDriverInfoEqual(info, driverInfo)
505
+ );
506
+ if (isDuplicateDriverInfo) return;
507
+
508
+ this.driverInfoList.push(driverInfo);
509
+ this.options.metadata = makeClientMetadata(this.driverInfoList, this.options);
497
510
  this.options.extendedMetadata = addContainerMetadata(this.options.metadata)
498
511
  .then(undefined, squashError)
499
512
  .then(result => result ?? {}); // ensure Promise<Document>
@@ -1094,7 +1107,9 @@ export interface MongoOptions
1094
1107
  dbName: string;
1095
1108
  /** @deprecated - Will be made internal in a future major release. */
1096
1109
  metadata: ClientMetadata;
1110
+ /** @deprecated - Will be made internal in a future major release. */
1097
1111
  extendedMetadata: Promise<Document>;
1112
+ /** @deprecated - Will be made internal in a future major release. */
1098
1113
  additionalDriverInfo: DriverInfo[];
1099
1114
  /** @internal */
1100
1115
  autoEncrypter?: AutoEncrypter;
@@ -1,17 +1,15 @@
1
- import { type Connection } from '..';
2
1
  import type { Document } from '../bson';
3
2
  import { CursorResponse, ExplainedCursorResponse } from '../cmap/wire_protocol/responses';
4
3
  import { type CursorTimeoutMode } from '../cursor/abstract_cursor';
5
4
  import { MongoInvalidArgumentError } from '../error';
6
5
  import { type ExplainOptions } from '../explain';
7
- import { maxWireVersion, type MongoDBNamespace } from '../utils';
6
+ import { type MongoDBNamespace } from '../utils';
8
7
  import { WriteConcern } from '../write_concern';
9
8
  import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
10
9
  import { Aspect, defineAspects, type Hint } from './operation';
11
10
 
12
11
  /** @internal */
13
12
  export const DB_AGGREGATE_COLLECTION = 1 as const;
14
- const MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT = 8;
15
13
 
16
14
  /** @public */
17
15
  export interface AggregateOptions extends Omit<CommandOperationOptions, 'explain'> {
@@ -107,15 +105,10 @@ export class AggregateOperation extends CommandOperation<CursorResponse> {
107
105
  this.pipeline.push(stage);
108
106
  }
109
107
 
110
- override buildCommandDocument(connection: Connection): Document {
108
+ override buildCommandDocument(): Document {
111
109
  const options = this.options;
112
- const serverWireVersion = maxWireVersion(connection);
113
110
  const command: Document = { aggregate: this.target, pipeline: this.pipeline };
114
111
 
115
- if (this.hasWriteStage && serverWireVersion < MIN_WIRE_VERSION_$OUT_READ_CONCERN_SUPPORT) {
116
- this.readConcern = undefined;
117
- }
118
-
119
112
  if (this.hasWriteStage && this.writeConcern) {
120
113
  WriteConcern.apply(command, this.writeConcern);
121
114
  }
@@ -161,5 +154,6 @@ defineAspects(AggregateOperation, [
161
154
  Aspect.READ_OPERATION,
162
155
  Aspect.RETRYABLE,
163
156
  Aspect.EXPLAINABLE,
164
- Aspect.CURSOR_CREATING
157
+ Aspect.CURSOR_CREATING,
158
+ Aspect.SUPPORTS_RAW_DATA
165
159
  ]);
@@ -67,5 +67,6 @@ defineAspects(ClientBulkWriteOperation, [
67
67
  Aspect.SKIP_COLLATION,
68
68
  Aspect.CURSOR_CREATING,
69
69
  Aspect.RETRYABLE,
70
- Aspect.COMMAND_BATCHING
70
+ Aspect.COMMAND_BATCHING,
71
+ Aspect.SUPPORTS_RAW_DATA
71
72
  ]);
@@ -1,5 +1,6 @@
1
1
  import { type Connection } from '..';
2
2
  import type { BSONSerializeOptions, Document } from '../bson';
3
+ import { MIN_SUPPORTED_RAW_DATA_WIRE_VERSION } from '../cmap/wire_protocol/constants';
3
4
  import { MongoInvalidArgumentError } from '../error';
4
5
  import {
5
6
  decorateWithExplain,
@@ -12,7 +13,7 @@ import type { ReadPreference } from '../read_preference';
12
13
  import type { ServerCommandOptions } from '../sdam/server';
13
14
  import type { ClientSession } from '../sessions';
14
15
  import { type TimeoutContext } from '../timeout';
15
- import { commandSupportsReadConcern, MongoDBNamespace } from '../utils';
16
+ import { commandSupportsReadConcern, maxWireVersion, MongoDBNamespace } from '../utils';
16
17
  import { WriteConcern, type WriteConcernOptions } from '../write_concern';
17
18
  import type { ReadConcernLike } from './../read_concern';
18
19
  import { AbstractOperation, Aspect, type OperationOptions } from './operation';
@@ -52,7 +53,11 @@ export interface CommandOperationOptions
52
53
  * In server versions 4.4 and above, 'comment' can be any valid BSON type.
53
54
  */
54
55
  comment?: unknown;
55
- /** Should retry failed writes */
56
+ /**
57
+ * @deprecated
58
+ * This option is deprecated and will be removed in a future release as it is not used
59
+ * in the driver. Use MongoClientOptions or connection string parameters instead.
60
+ * */
56
61
  retryWrites?: boolean;
57
62
 
58
63
  // Admin command overrides.
@@ -63,6 +68,14 @@ export interface CommandOperationOptions
63
68
  * This option is deprecated and will be removed in an upcoming major version.
64
69
  */
65
70
  noResponse?: boolean;
71
+
72
+ /**
73
+ * Used when the command needs to grant access to the underlying namespaces for time series collections.
74
+ * Only available on server versions 8.2 and above and is not meant for public use.
75
+ * @internal
76
+ * @sinceServerVersion 8.2
77
+ **/
78
+ rawData?: boolean;
66
79
  }
67
80
 
68
81
  /** @internal */
@@ -153,6 +166,14 @@ export abstract class CommandOperation<T> extends AbstractOperation<T> {
153
166
  command.maxTimeMS = this.options.maxTimeMS;
154
167
  }
155
168
 
169
+ if (
170
+ this.options.rawData != null &&
171
+ this.hasAspect(Aspect.SUPPORTS_RAW_DATA) &&
172
+ maxWireVersion(connection) >= MIN_SUPPORTED_RAW_DATA_WIRE_VERSION
173
+ ) {
174
+ command.rawData = this.options.rawData;
175
+ }
176
+
156
177
  if (this.hasAspect(Aspect.EXPLAINABLE) && this.explain) {
157
178
  return decorateWithExplain(command, this.explain);
158
179
  }
@@ -71,4 +71,4 @@ export class CountOperation extends CommandOperation<number> {
71
71
  }
72
72
  }
73
73
 
74
- defineAspects(CountOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE]);
74
+ defineAspects(CountOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.SUPPORTS_RAW_DATA]);
@@ -65,7 +65,7 @@ export interface ClusteredCollectionOptions extends Document {
65
65
  }
66
66
 
67
67
  /** @public */
68
- export interface CreateCollectionOptions extends CommandOperationOptions {
68
+ export interface CreateCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
69
69
  /** Create a capped collection */
70
70
  capped?: boolean;
71
71
  /** @deprecated Create an index on the _id field of the document. This option is deprecated in MongoDB 3.2+ and will be removed once no longer supported by the server. */
@@ -3,7 +3,7 @@ import { type Connection } from '../cmap/connection';
3
3
  import { MongoDBResponse } from '../cmap/wire_protocol/responses';
4
4
  import { MongoCompatibilityError, MongoServerError } from '../error';
5
5
  import type { ClientSession } from '../sessions';
6
- import { type MongoDBCollectionNamespace, type MongoDBNamespace } from '../utils';
6
+ import { maxWireVersion, type MongoDBCollectionNamespace, type MongoDBNamespace } from '../utils';
7
7
  import { type WriteConcernOptions } from '../write_concern';
8
8
  import { type CollationOptions, CommandOperation, type CommandOperationOptions } from './command';
9
9
  import { Aspect, defineAspects, type Hint } from './operation';
@@ -65,7 +65,7 @@ export class DeleteOperation extends CommandOperation<Document> {
65
65
  return this.statements.every(op => (op.limit != null ? op.limit > 0 : true));
66
66
  }
67
67
 
68
- override buildCommandDocument(_connection: Connection, _session?: ClientSession): Document {
68
+ override buildCommandDocument(connection: Connection, _session?: ClientSession): Document {
69
69
  const options = this.options;
70
70
 
71
71
  const ordered = typeof options.ordered === 'boolean' ? options.ordered : true;
@@ -86,10 +86,11 @@ export class DeleteOperation extends CommandOperation<Document> {
86
86
  }
87
87
 
88
88
  const unacknowledgedWrite = this.writeConcern && this.writeConcern.w === 0;
89
- if (unacknowledgedWrite) {
89
+ if (unacknowledgedWrite && maxWireVersion(connection) < 9) {
90
90
  if (this.statements.find((o: Document) => o.hint)) {
91
- // TODO(NODE-3541): fix error for hint with unacknowledged writes
92
- throw new MongoCompatibilityError(`hint is not supported with unacknowledged writes`);
91
+ throw new MongoCompatibilityError(
92
+ `hint for the delete command is only supported on MongoDB 4.4+`
93
+ );
93
94
  }
94
95
  }
95
96
 
@@ -162,15 +163,21 @@ export function makeDeleteStatement(
162
163
  return op;
163
164
  }
164
165
 
165
- defineAspects(DeleteOperation, [Aspect.RETRYABLE, Aspect.WRITE_OPERATION]);
166
+ defineAspects(DeleteOperation, [
167
+ Aspect.RETRYABLE,
168
+ Aspect.WRITE_OPERATION,
169
+ Aspect.SUPPORTS_RAW_DATA
170
+ ]);
166
171
  defineAspects(DeleteOneOperation, [
167
172
  Aspect.RETRYABLE,
168
173
  Aspect.WRITE_OPERATION,
169
174
  Aspect.EXPLAINABLE,
170
- Aspect.SKIP_COLLATION
175
+ Aspect.SKIP_COLLATION,
176
+ Aspect.SUPPORTS_RAW_DATA
171
177
  ]);
172
178
  defineAspects(DeleteManyOperation, [
173
179
  Aspect.WRITE_OPERATION,
174
180
  Aspect.EXPLAINABLE,
175
- Aspect.SKIP_COLLATION
181
+ Aspect.SKIP_COLLATION,
182
+ Aspect.SUPPORTS_RAW_DATA
176
183
  ]);
@@ -84,4 +84,9 @@ export class DistinctOperation extends CommandOperation<any[] | Document> {
84
84
  }
85
85
  }
86
86
 
87
- defineAspects(DistinctOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.EXPLAINABLE]);
87
+ defineAspects(DistinctOperation, [
88
+ Aspect.READ_OPERATION,
89
+ Aspect.RETRYABLE,
90
+ Aspect.EXPLAINABLE,
91
+ Aspect.SUPPORTS_RAW_DATA
92
+ ]);
@@ -11,7 +11,7 @@ import { executeOperation } from './execute_operation';
11
11
  import { Aspect, defineAspects } from './operation';
12
12
 
13
13
  /** @public */
14
- export interface DropCollectionOptions extends CommandOperationOptions {
14
+ export interface DropCollectionOptions extends Omit<CommandOperationOptions, 'rawData'> {
15
15
  /** @experimental */
16
16
  encryptedFields?: Document;
17
17
  }
@@ -56,5 +56,6 @@ export class EstimatedDocumentCountOperation extends CommandOperation<number> {
56
56
  defineAspects(EstimatedDocumentCountOperation, [
57
57
  Aspect.READ_OPERATION,
58
58
  Aspect.RETRYABLE,
59
- Aspect.CURSOR_CREATING
59
+ Aspect.CURSOR_CREATING,
60
+ Aspect.SUPPORTS_RAW_DATA
60
61
  ]);
@@ -258,5 +258,6 @@ defineAspects(FindOperation, [
258
258
  Aspect.READ_OPERATION,
259
259
  Aspect.RETRYABLE,
260
260
  Aspect.EXPLAINABLE,
261
- Aspect.CURSOR_CREATING
261
+ Aspect.CURSOR_CREATING,
262
+ Aspect.SUPPORTS_RAW_DATA
262
263
  ]);
@@ -6,7 +6,7 @@ import { MongoCompatibilityError, MongoInvalidArgumentError } from '../error';
6
6
  import { ReadPreference } from '../read_preference';
7
7
  import type { ClientSession } from '../sessions';
8
8
  import { formatSort, type Sort, type SortForCmd } from '../sort';
9
- import { decorateWithCollation, hasAtomicOperators } from '../utils';
9
+ import { decorateWithCollation, hasAtomicOperators, maxWireVersion } from '../utils';
10
10
  import { type WriteConcern, type WriteConcernSettings } from '../write_concern';
11
11
  import { CommandOperation, type CommandOperationOptions } from './command';
12
12
  import { Aspect, defineAspects } from './operation';
@@ -146,7 +146,7 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
146
146
  }
147
147
 
148
148
  override buildCommandDocument(
149
- _connection: Connection,
149
+ connection: Connection,
150
150
  _session?: ClientSession
151
151
  ): Document & FindAndModifyCmdBase {
152
152
  const options = this.options;
@@ -188,13 +188,13 @@ export class FindAndModifyOperation extends CommandOperation<Document> {
188
188
  command.comment = options.comment;
189
189
  }
190
190
 
191
- decorateWithCollation(command, this.collection, options);
191
+ decorateWithCollation(command, options);
192
192
 
193
193
  if (options.hint) {
194
194
  const unacknowledgedWrite = this.writeConcern?.w === 0;
195
- if (unacknowledgedWrite) {
195
+ if (unacknowledgedWrite && maxWireVersion(connection) < 9) {
196
196
  throw new MongoCompatibilityError(
197
- 'The current topology does not support a hint on findAndModify commands'
197
+ 'hint for the findAndModify command is only supported on MongoDB 4.4+'
198
198
  );
199
199
  }
200
200
 
@@ -314,5 +314,6 @@ export class FindOneAndUpdateOperation extends FindAndModifyOperation {
314
314
  defineAspects(FindAndModifyOperation, [
315
315
  Aspect.WRITE_OPERATION,
316
316
  Aspect.RETRYABLE,
317
- Aspect.EXPLAINABLE
317
+ Aspect.EXPLAINABLE,
318
+ Aspect.SUPPORTS_RAW_DATA
318
319
  ]);