mongodb 6.9.0 → 6.10.0

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 (127) hide show
  1. package/lib/beta.d.ts +407 -12
  2. package/lib/bson.js +1 -0
  3. package/lib/bson.js.map +1 -1
  4. package/lib/bulk/common.js +60 -71
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/bulk/unordered.js +3 -3
  7. package/lib/bulk/unordered.js.map +1 -1
  8. package/lib/change_stream.js +3 -2
  9. package/lib/change_stream.js.map +1 -1
  10. package/lib/cmap/auth/mongo_credentials.js +2 -7
  11. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  12. package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -1
  13. package/lib/cmap/auth/mongodb_oidc/command_builders.js +1 -1
  14. package/lib/cmap/auth/mongodb_oidc/command_builders.js.map +1 -1
  15. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js +1 -1
  16. package/lib/cmap/auth/mongodb_oidc/human_callback_workflow.js.map +1 -1
  17. package/lib/cmap/auth/mongodb_oidc/machine_workflow.js.map +1 -1
  18. package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
  19. package/lib/cmap/command_monitoring_events.js +10 -1
  20. package/lib/cmap/command_monitoring_events.js.map +1 -1
  21. package/lib/cmap/commands.js +50 -18
  22. package/lib/cmap/commands.js.map +1 -1
  23. package/lib/cmap/connection.js +9 -2
  24. package/lib/cmap/connection.js.map +1 -1
  25. package/lib/cmap/wire_protocol/constants.js +2 -2
  26. package/lib/cmap/wire_protocol/on_demand/document.js.map +1 -1
  27. package/lib/cmap/wire_protocol/responses.js +26 -1
  28. package/lib/cmap/wire_protocol/responses.js.map +1 -1
  29. package/lib/connection_string.js +1 -7
  30. package/lib/connection_string.js.map +1 -1
  31. package/lib/cursor/aggregation_cursor.js.map +1 -1
  32. package/lib/cursor/client_bulk_write_cursor.js +52 -0
  33. package/lib/cursor/client_bulk_write_cursor.js.map +1 -0
  34. package/lib/cursor/find_cursor.js.map +1 -1
  35. package/lib/db.js +1 -1
  36. package/lib/error.js +76 -3
  37. package/lib/error.js.map +1 -1
  38. package/lib/explain.js +6 -6
  39. package/lib/explain.js.map +1 -1
  40. package/lib/index.js +6 -3
  41. package/lib/index.js.map +1 -1
  42. package/lib/mongo_client.js +14 -0
  43. package/lib/mongo_client.js.map +1 -1
  44. package/lib/mongo_client_auth_providers.js +6 -2
  45. package/lib/mongo_client_auth_providers.js.map +1 -1
  46. package/lib/mongo_types.js.map +1 -1
  47. package/lib/operations/aggregate.js.map +1 -1
  48. package/lib/operations/client_bulk_write/client_bulk_write.js +83 -0
  49. package/lib/operations/client_bulk_write/client_bulk_write.js.map +1 -0
  50. package/lib/operations/client_bulk_write/command_builder.js +154 -19
  51. package/lib/operations/client_bulk_write/command_builder.js.map +1 -1
  52. package/lib/operations/client_bulk_write/executor.js +109 -0
  53. package/lib/operations/client_bulk_write/executor.js.map +1 -0
  54. package/lib/operations/client_bulk_write/results_merger.js +204 -0
  55. package/lib/operations/client_bulk_write/results_merger.js.map +1 -0
  56. package/lib/operations/execute_operation.js +7 -0
  57. package/lib/operations/execute_operation.js.map +1 -1
  58. package/lib/operations/find.js.map +1 -1
  59. package/lib/operations/operation.js +5 -1
  60. package/lib/operations/operation.js.map +1 -1
  61. package/lib/operations/search_indexes/create.js.map +1 -1
  62. package/lib/operations/search_indexes/drop.js.map +1 -1
  63. package/lib/operations/search_indexes/update.js.map +1 -1
  64. package/lib/sdam/server.js +2 -1
  65. package/lib/sdam/server.js.map +1 -1
  66. package/lib/sdam/server_description.js +3 -0
  67. package/lib/sdam/server_description.js.map +1 -1
  68. package/lib/sdam/srv_polling.js +5 -1
  69. package/lib/sdam/srv_polling.js.map +1 -1
  70. package/lib/sdam/topology_description.js.map +1 -1
  71. package/lib/sessions.js +9 -2
  72. package/lib/sessions.js.map +1 -1
  73. package/lib/utils.js +25 -9
  74. package/lib/utils.js.map +1 -1
  75. package/lib/write_concern.js.map +1 -1
  76. package/mongodb.d.ts +407 -12
  77. package/package.json +1 -1
  78. package/src/beta.ts +1 -1
  79. package/src/bson.ts +3 -0
  80. package/src/bulk/common.ts +80 -120
  81. package/src/bulk/unordered.ts +3 -4
  82. package/src/change_stream.ts +5 -2
  83. package/src/cmap/auth/mongo_credentials.ts +2 -8
  84. package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +1 -1
  85. package/src/cmap/auth/mongodb_oidc/command_builders.ts +1 -2
  86. package/src/cmap/auth/mongodb_oidc/human_callback_workflow.ts +1 -2
  87. package/src/cmap/auth/mongodb_oidc/machine_workflow.ts +1 -1
  88. package/src/cmap/auth/mongodb_oidc.ts +1 -2
  89. package/src/cmap/command_monitoring_events.ts +16 -2
  90. package/src/cmap/commands.ts +71 -25
  91. package/src/cmap/connection.ts +17 -4
  92. package/src/cmap/wire_protocol/constants.ts +2 -2
  93. package/src/cmap/wire_protocol/on_demand/document.ts +1 -2
  94. package/src/cmap/wire_protocol/responses.ts +31 -2
  95. package/src/connection_string.ts +2 -9
  96. package/src/cursor/aggregation_cursor.ts +2 -2
  97. package/src/cursor/client_bulk_write_cursor.ts +79 -0
  98. package/src/cursor/find_cursor.ts +2 -2
  99. package/src/db.ts +1 -1
  100. package/src/error.ts +98 -2
  101. package/src/explain.ts +47 -11
  102. package/src/index.ts +26 -1
  103. package/src/mongo_client.ts +29 -1
  104. package/src/mongo_client_auth_providers.ts +8 -2
  105. package/src/mongo_types.ts +2 -1
  106. package/src/operations/aggregate.ts +9 -1
  107. package/src/operations/client_bulk_write/client_bulk_write.ts +107 -0
  108. package/src/operations/client_bulk_write/command_builder.ts +216 -30
  109. package/src/operations/client_bulk_write/common.ts +148 -23
  110. package/src/operations/client_bulk_write/executor.ts +137 -0
  111. package/src/operations/client_bulk_write/results_merger.ts +260 -0
  112. package/src/operations/execute_operation.ts +8 -0
  113. package/src/operations/find.ts +8 -1
  114. package/src/operations/operation.ts +6 -1
  115. package/src/operations/search_indexes/create.ts +1 -2
  116. package/src/operations/search_indexes/drop.ts +1 -2
  117. package/src/operations/search_indexes/update.ts +1 -2
  118. package/src/sdam/server.ts +2 -1
  119. package/src/sdam/server_description.ts +9 -0
  120. package/src/sdam/srv_polling.ts +5 -2
  121. package/src/sdam/topology_description.ts +0 -1
  122. package/src/sessions.ts +16 -2
  123. package/src/utils.ts +40 -10
  124. package/src/write_concern.ts +4 -1
  125. package/lib/cmap/auth/mongocr.js +0 -35
  126. package/lib/cmap/auth/mongocr.js.map +0 -1
  127. package/src/cmap/auth/mongocr.ts +0 -38
package/mongodb.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { ObjectIdLike } from 'bson';
2
1
  import type { DeserializeOptions } from 'bson';
2
+ import type { ObjectIdLike } from 'bson';
3
3
  import type { SerializeOptions } from 'bson';
4
4
  import { Binary } from 'bson';
5
5
  import { BSON } from 'bson';
@@ -368,7 +368,7 @@ export declare class Admin {
368
368
  /* Excluded from this release type: AggregateOperation */
369
369
 
370
370
  /** @public */
371
- export declare interface AggregateOptions extends CommandOperationOptions {
371
+ export declare interface AggregateOptions extends Omit<CommandOperationOptions, 'explain'> {
372
372
  /** allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 \>). */
373
373
  allowDiskUse?: boolean;
374
374
  /** The number of documents to return per batch. See [aggregation documentation](https://www.mongodb.com/docs/manual/reference/command/aggregate). */
@@ -388,6 +388,12 @@ export declare interface AggregateOptions extends CommandOperationOptions {
388
388
  /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
389
389
  let?: Document;
390
390
  out?: string;
391
+ /**
392
+ * Specifies the verbosity mode for the explain output.
393
+ * @deprecated This API is deprecated in favor of `collection.aggregate().explain()`
394
+ * or `db.aggregate().explain()`.
395
+ */
396
+ explain?: ExplainOptions['explain'];
391
397
  }
392
398
 
393
399
  /**
@@ -405,7 +411,7 @@ export declare class AggregationCursor<TSchema = any> extends AbstractCursor<TSc
405
411
  map<T>(transform: (doc: TSchema) => T): AggregationCursor<T>;
406
412
  /* Excluded from this release type: _initialize */
407
413
  /** Execute the explain for the cursor */
408
- explain(verbosity?: ExplainVerbosityLike): Promise<Document>;
414
+ explain(verbosity?: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
409
415
  /** Add a stage to the aggregation pipeline
410
416
  * @example
411
417
  * ```
@@ -514,6 +520,13 @@ export declare type AnyBulkWriteOperation<TSchema extends Document = Document> =
514
520
  deleteMany: DeleteManyModel<TSchema>;
515
521
  };
516
522
 
523
+ /**
524
+ * Used to represent any of the client bulk write models that can be passed as an array
525
+ * to MongoClient#bulkWrite.
526
+ * @public
527
+ */
528
+ export declare type AnyClientBulkWriteModel<TSchema extends Document> = ClientInsertOneModel<TSchema> | ClientReplaceOneModel<TSchema> | ClientUpdateOneModel<TSchema> | ClientUpdateManyModel<TSchema> | ClientDeleteOneModel<TSchema> | ClientDeleteManyModel<TSchema>;
529
+
517
530
  /** @public */
518
531
  export declare type AnyError = MongoError | Error;
519
532
 
@@ -1480,6 +1493,137 @@ export declare interface ChangeStreamUpdateDocument<TSchema extends Document = D
1480
1493
  fullDocumentBeforeChange?: TSchema;
1481
1494
  }
1482
1495
 
1496
+ /** @public */
1497
+ export declare interface ClientBulkWriteError {
1498
+ code: number;
1499
+ message: string;
1500
+ }
1501
+
1502
+ /**
1503
+ * A mapping of namespace strings to collections schemas.
1504
+ * @public
1505
+ *
1506
+ * @example
1507
+ * ```ts
1508
+ * type MongoDBSchemas = {
1509
+ * 'db.books': Book;
1510
+ * 'db.authors': Author;
1511
+ * }
1512
+ *
1513
+ * const model: ClientBulkWriteModel<MongoDBSchemas> = {
1514
+ * namespace: 'db.books'
1515
+ * name: 'insertOne',
1516
+ * document: { title: 'Practical MongoDB Aggregations', authorName: 3 } // error `authorName` cannot be number
1517
+ * };
1518
+ * ```
1519
+ *
1520
+ * The type of the `namespace` field narrows other parts of the BulkWriteModel to use the correct schema for type assertions.
1521
+ *
1522
+ */
1523
+ export declare type ClientBulkWriteModel<SchemaMap extends Record<string, Document> = Record<string, Document>> = {
1524
+ [Namespace in keyof SchemaMap]: AnyClientBulkWriteModel<SchemaMap[Namespace]> & {
1525
+ namespace: Namespace;
1526
+ };
1527
+ }[keyof SchemaMap];
1528
+
1529
+ /** @public */
1530
+ export declare interface ClientBulkWriteOptions extends CommandOperationOptions {
1531
+ /**
1532
+ * If true, when an insert fails, don't execute the remaining writes.
1533
+ * If false, continue with remaining inserts when one fails.
1534
+ * @defaultValue `true` - inserts are ordered by default
1535
+ */
1536
+ ordered?: boolean;
1537
+ /**
1538
+ * Allow driver to bypass schema validation.
1539
+ * @defaultValue `false` - documents will be validated by default
1540
+ **/
1541
+ bypassDocumentValidation?: boolean;
1542
+ /** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
1543
+ let?: Document;
1544
+ /**
1545
+ * Whether detailed results for each successful operation should be included in the returned
1546
+ * BulkWriteResult.
1547
+ */
1548
+ verboseResults?: boolean;
1549
+ }
1550
+
1551
+ /** @public */
1552
+ export declare interface ClientBulkWriteResult {
1553
+ /**
1554
+ * Whether the bulk write was acknowledged.
1555
+ */
1556
+ readonly acknowledged: boolean;
1557
+ /**
1558
+ * The total number of documents inserted across all insert operations.
1559
+ */
1560
+ readonly insertedCount: number;
1561
+ /**
1562
+ * The total number of documents upserted across all update operations.
1563
+ */
1564
+ readonly upsertedCount: number;
1565
+ /**
1566
+ * The total number of documents matched across all update operations.
1567
+ */
1568
+ readonly matchedCount: number;
1569
+ /**
1570
+ * The total number of documents modified across all update operations.
1571
+ */
1572
+ readonly modifiedCount: number;
1573
+ /**
1574
+ * The total number of documents deleted across all delete operations.
1575
+ */
1576
+ readonly deletedCount: number;
1577
+ /**
1578
+ * The results of each individual insert operation that was successfully performed.
1579
+ */
1580
+ readonly insertResults?: ReadonlyMap<number, ClientInsertOneResult>;
1581
+ /**
1582
+ * The results of each individual update operation that was successfully performed.
1583
+ */
1584
+ readonly updateResults?: ReadonlyMap<number, ClientUpdateResult>;
1585
+ /**
1586
+ * The results of each individual delete operation that was successfully performed.
1587
+ */
1588
+ readonly deleteResults?: ReadonlyMap<number, ClientDeleteResult>;
1589
+ }
1590
+
1591
+ /** @public */
1592
+ export declare interface ClientDeleteManyModel<TSchema> extends ClientWriteModel {
1593
+ name: 'deleteMany';
1594
+ /**
1595
+ * The filter used to determine if a document should be deleted.
1596
+ * For a deleteMany operation, all matches are removed.
1597
+ */
1598
+ filter: Filter<TSchema>;
1599
+ /** Specifies a collation. */
1600
+ collation?: CollationOptions;
1601
+ /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
1602
+ hint?: Hint;
1603
+ }
1604
+
1605
+ /** @public */
1606
+ export declare interface ClientDeleteOneModel<TSchema> extends ClientWriteModel {
1607
+ name: 'deleteOne';
1608
+ /**
1609
+ * The filter used to determine if a document should be deleted.
1610
+ * For a deleteOne operation, the first match is removed.
1611
+ */
1612
+ filter: Filter<TSchema>;
1613
+ /** Specifies a collation. */
1614
+ collation?: CollationOptions;
1615
+ /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
1616
+ hint?: Hint;
1617
+ }
1618
+
1619
+ /** @public */
1620
+ export declare interface ClientDeleteResult {
1621
+ /**
1622
+ * The number of documents that were deleted.
1623
+ */
1624
+ deletedCount: number;
1625
+ }
1626
+
1483
1627
  /**
1484
1628
  * @public
1485
1629
  * The public interface for explicit in-use encryption
@@ -1901,6 +2045,21 @@ export declare type ClientEncryptionSocketOptions = Pick<MongoClientOptions, 'au
1901
2045
  */
1902
2046
  export declare type ClientEncryptionTlsOptions = Pick<MongoClientOptions, 'tlsCAFile' | 'tlsCertificateKeyFile' | 'tlsCertificateKeyFilePassword'>;
1903
2047
 
2048
+ /** @public */
2049
+ export declare interface ClientInsertOneModel<TSchema> extends ClientWriteModel {
2050
+ name: 'insertOne';
2051
+ /** The document to insert. */
2052
+ document: OptionalId<TSchema>;
2053
+ }
2054
+
2055
+ /** @public */
2056
+ export declare interface ClientInsertOneResult {
2057
+ /**
2058
+ * The _id of the inserted document.
2059
+ */
2060
+ insertedId: any;
2061
+ }
2062
+
1904
2063
  /**
1905
2064
  * @public
1906
2065
  * @see https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#hello-command
@@ -1940,6 +2099,24 @@ export declare interface ClientMetadataOptions {
1940
2099
  appName?: string;
1941
2100
  }
1942
2101
 
2102
+ /** @public */
2103
+ export declare interface ClientReplaceOneModel<TSchema> extends ClientWriteModel {
2104
+ name: 'replaceOne';
2105
+ /**
2106
+ * The filter used to determine if a document should be replaced.
2107
+ * For a replaceOne operation, the first match is replaced.
2108
+ */
2109
+ filter: Filter<TSchema>;
2110
+ /** The document with which to replace the matched document. */
2111
+ replacement: WithoutId<TSchema>;
2112
+ /** Specifies a collation. */
2113
+ collation?: CollationOptions;
2114
+ /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
2115
+ hint?: Hint;
2116
+ /** When true, creates a new document if no document matches the query. */
2117
+ upsert?: boolean;
2118
+ }
2119
+
1943
2120
  /**
1944
2121
  * A class representing a client session on the server
1945
2122
  *
@@ -1960,6 +2137,7 @@ export declare class ClientSession extends TypedEventEmitter<ClientSessionEvents
1960
2137
  /* Excluded from this release type: owner */
1961
2138
  defaultTransactionOptions: TransactionOptions;
1962
2139
  transaction: Transaction;
2140
+ /* Excluded from this release type: commitAttempted */
1963
2141
  /* Excluded from this release type: [kServerSession] */
1964
2142
  /* Excluded from this release type: [kSnapshotTime] */
1965
2143
  /* Excluded from this release type: [kSnapshotEnabled] */
@@ -2094,6 +2272,91 @@ export declare interface ClientSessionOptions {
2094
2272
  /* Excluded from this release type: initialClusterTime */
2095
2273
  }
2096
2274
 
2275
+ /** @public */
2276
+ export declare interface ClientUpdateManyModel<TSchema> extends ClientWriteModel {
2277
+ name: 'updateMany';
2278
+ /**
2279
+ * The filter used to determine if a document should be updated.
2280
+ * For an updateMany operation, all matches are updated.
2281
+ */
2282
+ filter: Filter<TSchema>;
2283
+ /**
2284
+ * The modifications to apply. The value can be either:
2285
+ * UpdateFilter<Document> - A document that contains update operator expressions,
2286
+ * Document[] - an aggregation pipeline.
2287
+ */
2288
+ update: UpdateFilter<TSchema> | Document[];
2289
+ /** A set of filters specifying to which array elements an update should apply. */
2290
+ arrayFilters?: Document[];
2291
+ /** Specifies a collation. */
2292
+ collation?: CollationOptions;
2293
+ /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
2294
+ hint?: Hint;
2295
+ /** When true, creates a new document if no document matches the query. */
2296
+ upsert?: boolean;
2297
+ }
2298
+
2299
+ /** @public */
2300
+ export declare interface ClientUpdateOneModel<TSchema> extends ClientWriteModel {
2301
+ name: 'updateOne';
2302
+ /**
2303
+ * The filter used to determine if a document should be updated.
2304
+ * For an updateOne operation, the first match is updated.
2305
+ */
2306
+ filter: Filter<TSchema>;
2307
+ /**
2308
+ * The modifications to apply. The value can be either:
2309
+ * UpdateFilter<Document> - A document that contains update operator expressions,
2310
+ * Document[] - an aggregation pipeline.
2311
+ */
2312
+ update: UpdateFilter<TSchema> | Document[];
2313
+ /** A set of filters specifying to which array elements an update should apply. */
2314
+ arrayFilters?: Document[];
2315
+ /** Specifies a collation. */
2316
+ collation?: CollationOptions;
2317
+ /** The index to use. If specified, then the query system will only consider plans using the hinted index. */
2318
+ hint?: Hint;
2319
+ /** When true, creates a new document if no document matches the query. */
2320
+ upsert?: boolean;
2321
+ }
2322
+
2323
+ /** @public */
2324
+ export declare interface ClientUpdateResult {
2325
+ /**
2326
+ * The number of documents that matched the filter.
2327
+ */
2328
+ matchedCount: number;
2329
+ /**
2330
+ * The number of documents that were modified.
2331
+ */
2332
+ modifiedCount: number;
2333
+ /**
2334
+ * The _id field of the upserted document if an upsert occurred.
2335
+ *
2336
+ * It MUST be possible to discern between a BSON Null upserted ID value and this field being
2337
+ * unset. If necessary, drivers MAY add a didUpsert boolean field to differentiate between
2338
+ * these two cases.
2339
+ */
2340
+ upsertedId?: any;
2341
+ /**
2342
+ * Determines if the upsert did include an _id, which includes the case of the _id being null.
2343
+ */
2344
+ didUpsert: boolean;
2345
+ }
2346
+
2347
+ /** @public */
2348
+ export declare interface ClientWriteModel {
2349
+ /**
2350
+ * The namespace for the write.
2351
+ *
2352
+ * A namespace is a combination of the database name and the name of the collection: `<database-name>.<collection>`.
2353
+ * All documents belong to a namespace.
2354
+ *
2355
+ * @see https://www.mongodb.com/docs/manual/reference/limits/#std-label-faq-dev-namespace
2356
+ */
2357
+ namespace: string;
2358
+ }
2359
+
2097
2360
  /**
2098
2361
  * @public
2099
2362
  * @deprecated This interface is deprecated and will be removed in a future release as it is not used
@@ -3333,7 +3596,7 @@ export declare class Db {
3333
3596
  */
3334
3597
  command(command: Document, options?: RunCommandOptions): Promise<Document>;
3335
3598
  /**
3336
- * Execute an aggregation framework pipeline against the database, needs MongoDB \>= 3.6
3599
+ * Execute an aggregation framework pipeline against the database.
3337
3600
  *
3338
3601
  * @param pipeline - An array of aggregation stages to be executed
3339
3602
  * @param options - Optional settings for the command
@@ -3626,9 +3889,45 @@ export declare type EventsDescription = Record<string, GenericListener>;
3626
3889
  /* Excluded from this release type: Explain */
3627
3890
 
3628
3891
  /** @public */
3892
+ export declare interface ExplainCommandOptions {
3893
+ /** The explain verbosity for the command. */
3894
+ verbosity: ExplainVerbosity;
3895
+ /** The maxTimeMS setting for the command. */
3896
+ maxTimeMS?: number;
3897
+ }
3898
+
3899
+ /**
3900
+ * @public
3901
+ *
3902
+ * When set, this configures an explain command. Valid values are boolean (for legacy compatibility,
3903
+ * see {@link ExplainVerbosityLike}), a string containing the explain verbosity, or an object containing the verbosity and
3904
+ * an optional maxTimeMS.
3905
+ *
3906
+ * Examples of valid usage:
3907
+ *
3908
+ * ```typescript
3909
+ * collection.find({ name: 'john doe' }, { explain: true });
3910
+ * collection.find({ name: 'john doe' }, { explain: false });
3911
+ * collection.find({ name: 'john doe' }, { explain: 'queryPlanner' });
3912
+ * collection.find({ name: 'john doe' }, { explain: { verbosity: 'queryPlanner' } });
3913
+ * ```
3914
+ *
3915
+ * maxTimeMS can be configured to limit the amount of time the server
3916
+ * spends executing an explain by providing an object:
3917
+ *
3918
+ * ```typescript
3919
+ * // limits the `explain` command to no more than 2 seconds
3920
+ * collection.find({ name: 'john doe' }, {
3921
+ * explain: {
3922
+ * verbosity: 'queryPlanner',
3923
+ * maxTimeMS: 2000
3924
+ * }
3925
+ * });
3926
+ * ```
3927
+ */
3629
3928
  export declare interface ExplainOptions {
3630
3929
  /** Specifies the verbosity mode for the explain output. */
3631
- explain?: ExplainVerbosityLike;
3930
+ explain?: ExplainVerbosityLike | ExplainCommandOptions;
3632
3931
  }
3633
3932
 
3634
3933
  /** @public */
@@ -3644,8 +3943,7 @@ export declare type ExplainVerbosity = string;
3644
3943
 
3645
3944
  /**
3646
3945
  * For backwards compatibility, true is interpreted as "allPlansExecution"
3647
- * and false as "queryPlanner". Prior to server version 3.6, aggregate()
3648
- * ignores the verbosity parameter and executes in "queryPlanner".
3946
+ * and false as "queryPlanner".
3649
3947
  * @public
3650
3948
  */
3651
3949
  export declare type ExplainVerbosityLike = ExplainVerbosity | boolean;
@@ -3715,7 +4013,7 @@ export declare class FindCursor<TSchema = any> extends AbstractCursor<TSchema> {
3715
4013
  */
3716
4014
  count(options?: CountOptions): Promise<number>;
3717
4015
  /** Execute the explain for the cursor */
3718
- explain(verbosity?: ExplainVerbosityLike): Promise<Document>;
4016
+ explain(verbosity?: ExplainVerbosityLike | ExplainCommandOptions): Promise<Document>;
3719
4017
  /** Set the cursor query */
3720
4018
  filter(filter: Document): this;
3721
4019
  /**
@@ -3945,7 +4243,7 @@ export declare class FindOperators {
3945
4243
  * @public
3946
4244
  * @typeParam TSchema - Unused schema definition, deprecated usage, only specify `FindOptions` with no generic
3947
4245
  */
3948
- export declare interface FindOptions<TSchema extends Document = Document> extends Omit<CommandOperationOptions, 'writeConcern'> {
4246
+ export declare interface FindOptions<TSchema extends Document = Document> extends Omit<CommandOperationOptions, 'writeConcern' | 'explain'> {
3949
4247
  /** Sets the limit of documents returned in the query. */
3950
4248
  limit?: number;
3951
4249
  /** Set to sort the documents coming back from the query. Array of indexes, `[['a', 1]]` etc. */
@@ -3993,6 +4291,11 @@ export declare interface FindOptions<TSchema extends Document = Document> extend
3993
4291
  * @deprecated Starting from MongoDB 4.4 this flag is not needed and will be ignored.
3994
4292
  */
3995
4293
  oplogReplay?: boolean;
4294
+ /**
4295
+ * Specifies the verbosity mode for the explain output.
4296
+ * @deprecated This API is deprecated in favor of `collection.find().explain()`.
4297
+ */
4298
+ explain?: ExplainOptions['explain'];
3996
4299
  }
3997
4300
 
3998
4301
  /** @public */
@@ -4966,6 +5269,13 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
4966
5269
  get writeConcern(): WriteConcern | undefined;
4967
5270
  get readPreference(): ReadPreference;
4968
5271
  get bsonOptions(): BSONSerializeOptions;
5272
+ /**
5273
+ * Executes a client bulk write operation, available on server 8.0+.
5274
+ * @param models - The client bulk write models.
5275
+ * @param options - The client bulk write options.
5276
+ * @returns A ClientBulkWriteResult for acknowledged writes and ok: 1 for unacknowledged writes.
5277
+ */
5278
+ bulkWrite<SchemaMap extends Record<string, Document> = Record<string, Document>>(models: ReadonlyArray<ClientBulkWriteModel<SchemaMap>>, options?: ClientBulkWriteOptions): Promise<ClientBulkWriteResult>;
4969
5279
  /**
4970
5280
  * Connect to MongoDB using a url
4971
5281
  *
@@ -5041,6 +5351,80 @@ export declare class MongoClient extends TypedEventEmitter<MongoClientEvents> im
5041
5351
 
5042
5352
  /* Excluded from this release type: MongoClientAuthProviders */
5043
5353
 
5354
+ /**
5355
+ * An error indicating that an error occurred when processing bulk write results.
5356
+ *
5357
+ * @public
5358
+ * @category Error
5359
+ */
5360
+ export declare class MongoClientBulkWriteCursorError extends MongoRuntimeError {
5361
+ /**
5362
+ * **Do not use this constructor!**
5363
+ *
5364
+ * Meant for internal use only.
5365
+ *
5366
+ * @remarks
5367
+ * This class is only meant to be constructed within the driver. This constructor is
5368
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
5369
+ *
5370
+ * @public
5371
+ **/
5372
+ constructor(message: string);
5373
+ get name(): string;
5374
+ }
5375
+
5376
+ /**
5377
+ * An error indicating that an error occurred when executing the bulk write.
5378
+ *
5379
+ * @public
5380
+ * @category Error
5381
+ */
5382
+ export declare class MongoClientBulkWriteError extends MongoServerError {
5383
+ /**
5384
+ * Write concern errors that occurred while executing the bulk write. This list may have
5385
+ * multiple items if more than one server command was required to execute the bulk write.
5386
+ */
5387
+ writeConcernErrors: Document[];
5388
+ /**
5389
+ * Errors that occurred during the execution of individual write operations. This map will
5390
+ * contain at most one entry if the bulk write was ordered.
5391
+ */
5392
+ writeErrors: Map<number, ClientBulkWriteError>;
5393
+ /**
5394
+ * The results of any successful operations that were performed before the error was
5395
+ * encountered.
5396
+ */
5397
+ partialResult?: ClientBulkWriteResult;
5398
+ /**
5399
+ * Initialize the client bulk write error.
5400
+ * @param message - The error message.
5401
+ */
5402
+ constructor(message: ErrorDescription);
5403
+ get name(): string;
5404
+ }
5405
+
5406
+ /**
5407
+ * An error indicating that an error occurred on the client when executing a client bulk write.
5408
+ *
5409
+ * @public
5410
+ * @category Error
5411
+ */
5412
+ export declare class MongoClientBulkWriteExecutionError extends MongoRuntimeError {
5413
+ /**
5414
+ * **Do not use this constructor!**
5415
+ *
5416
+ * Meant for internal use only.
5417
+ *
5418
+ * @remarks
5419
+ * This class is only meant to be constructed within the driver. This constructor is
5420
+ * not subject to semantic versioning compatibility guarantees and may change at any time.
5421
+ *
5422
+ * @public
5423
+ **/
5424
+ constructor(message: string);
5425
+ get name(): string;
5426
+ }
5427
+
5044
5428
  /** @public */
5045
5429
  export declare type MongoClientEvents = Pick<TopologyEvents, (typeof MONGO_CLIENT_EVENTS)[number]> & {
5046
5430
  open(mongoClient: MongoClient): void;
@@ -5688,7 +6072,9 @@ export declare class MongoInvalidArgumentError extends MongoAPIError {
5688
6072
  *
5689
6073
  * @public
5690
6074
  **/
5691
- constructor(message: string);
6075
+ constructor(message: string, options?: {
6076
+ cause?: Error;
6077
+ });
5692
6078
  get name(): string;
5693
6079
  }
5694
6080
 
@@ -6925,6 +7311,12 @@ export declare class ServerDescription {
6925
7311
  setVersion: number | null;
6926
7312
  electionId: ObjectId | null;
6927
7313
  logicalSessionTimeoutMinutes: number | null;
7314
+ /** The max message size in bytes for the server. */
7315
+ maxMessageSizeBytes: number | null;
7316
+ /** The max number of writes in a bulk write command. */
7317
+ maxWriteBatchSize: number | null;
7318
+ /** The max bson object size. */
7319
+ maxBsonObjectSize: number | null;
6928
7320
  $clusterTime?: ClusterTime;
6929
7321
  /* Excluded from this release type: __constructor */
6930
7322
  get hostAddress(): HostAddress;
@@ -7508,7 +7900,7 @@ export declare class TypedEventEmitter<Events extends EventsDescription> extends
7508
7900
  /** @public */
7509
7901
  export declare class UnorderedBulkOperation extends BulkOperationBase {
7510
7902
  /* Excluded from this release type: __constructor */
7511
- handleWriteError(callback: Callback, writeResult: BulkWriteResult): boolean;
7903
+ handleWriteError(writeResult: BulkWriteResult): void;
7512
7904
  addToOperationsList(batchType: BatchType, document: Document | UpdateStatement | DeleteStatement): this;
7513
7905
  }
7514
7906
 
@@ -7716,7 +8108,10 @@ export declare type WithTransactionCallback<T = any> = (session: ClientSession)
7716
8108
  * @see https://www.mongodb.com/docs/manual/reference/write-concern/
7717
8109
  */
7718
8110
  export declare class WriteConcern {
7719
- /** Request acknowledgment that the write operation has propagated to a specified number of mongod instances or to mongod instances with specified tags. */
8111
+ /**
8112
+ * Request acknowledgment that the write operation has propagated to a specified number of mongod instances or to mongod instances with specified tags.
8113
+ * If w is 0 and is set on a write operation, the server will not send a response.
8114
+ */
7720
8115
  readonly w?: W;
7721
8116
  /** Request acknowledgment that the write operation has been written to the on-disk journal */
7722
8117
  readonly journal?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "6.9.0",
3
+ "version": "6.10.0",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
package/src/beta.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Document } from 'bson';
1
+ import { type Document } from './bson';
2
2
 
3
3
  export * from './index';
4
4
 
package/src/bson.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /* eslint-disable no-restricted-imports */
1
2
  import { BSON, type DeserializeOptions, type SerializeOptions } from 'bson';
2
3
 
3
4
  export {
@@ -12,6 +13,7 @@ export {
12
13
  DBRef,
13
14
  Decimal128,
14
15
  deserialize,
16
+ type DeserializeOptions,
15
17
  Document,
16
18
  Double,
17
19
  EJSON,
@@ -21,6 +23,7 @@ export {
21
23
  MaxKey,
22
24
  MinKey,
23
25
  ObjectId,
26
+ type ObjectIdLike,
24
27
  serialize,
25
28
  Timestamp,
26
29
  UUID