mongodb 4.1.1 → 4.2.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 (174) hide show
  1. package/README.md +24 -17
  2. package/lib/admin.js +5 -5
  3. package/lib/admin.js.map +1 -1
  4. package/lib/bulk/common.js +60 -56
  5. package/lib/bulk/common.js.map +1 -1
  6. package/lib/change_stream.js +15 -13
  7. package/lib/change_stream.js.map +1 -1
  8. package/lib/cmap/auth/gssapi.js +1 -1
  9. package/lib/cmap/auth/gssapi.js.map +1 -1
  10. package/lib/cmap/auth/mongo_credentials.js +2 -1
  11. package/lib/cmap/auth/mongo_credentials.js.map +1 -1
  12. package/lib/cmap/auth/mongocr.js +2 -2
  13. package/lib/cmap/auth/mongocr.js.map +1 -1
  14. package/lib/cmap/auth/mongodb_aws.js +23 -28
  15. package/lib/cmap/auth/mongodb_aws.js.map +1 -1
  16. package/lib/cmap/auth/plain.js +1 -1
  17. package/lib/cmap/auth/plain.js.map +1 -1
  18. package/lib/cmap/auth/scram.js +5 -5
  19. package/lib/cmap/auth/scram.js.map +1 -1
  20. package/lib/cmap/auth/x509.js +1 -1
  21. package/lib/cmap/auth/x509.js.map +1 -1
  22. package/lib/cmap/command_monitoring_events.js +15 -15
  23. package/lib/cmap/command_monitoring_events.js.map +1 -1
  24. package/lib/cmap/commands.js +1 -1
  25. package/lib/cmap/commands.js.map +1 -1
  26. package/lib/cmap/connect.js +2 -2
  27. package/lib/cmap/connect.js.map +1 -1
  28. package/lib/cmap/connection.js +15 -15
  29. package/lib/cmap/connection.js.map +1 -1
  30. package/lib/cmap/connection_pool.js +3 -3
  31. package/lib/cmap/connection_pool.js.map +1 -1
  32. package/lib/cmap/message_stream.js +2 -2
  33. package/lib/cmap/message_stream.js.map +1 -1
  34. package/lib/cmap/stream_description.js +1 -1
  35. package/lib/cmap/stream_description.js.map +1 -1
  36. package/lib/cmap/wire_protocol/constants.js +4 -4
  37. package/lib/collection.js +42 -41
  38. package/lib/collection.js.map +1 -1
  39. package/lib/connection_string.js +94 -58
  40. package/lib/connection_string.js.map +1 -1
  41. package/lib/cursor/abstract_cursor.js +11 -11
  42. package/lib/cursor/abstract_cursor.js.map +1 -1
  43. package/lib/cursor/aggregation_cursor.js +15 -15
  44. package/lib/cursor/aggregation_cursor.js.map +1 -1
  45. package/lib/cursor/find_cursor.js +23 -23
  46. package/lib/cursor/find_cursor.js.map +1 -1
  47. package/lib/db.js +20 -20
  48. package/lib/db.js.map +1 -1
  49. package/lib/deps.js +1 -1
  50. package/lib/deps.js.map +1 -1
  51. package/lib/gridfs/index.js +3 -3
  52. package/lib/gridfs/index.js.map +1 -1
  53. package/lib/gridfs/upload.js +1 -1
  54. package/lib/gridfs/upload.js.map +1 -1
  55. package/lib/index.js +8 -2
  56. package/lib/index.js.map +1 -1
  57. package/lib/logger.js +5 -5
  58. package/lib/logger.js.map +1 -1
  59. package/lib/mongo_client.js +7 -7
  60. package/lib/mongo_client.js.map +1 -1
  61. package/lib/mongo_types.js.map +1 -1
  62. package/lib/operations/add_user.js +3 -3
  63. package/lib/operations/add_user.js.map +1 -1
  64. package/lib/operations/aggregate.js +3 -4
  65. package/lib/operations/aggregate.js.map +1 -1
  66. package/lib/operations/bulk_write.js +1 -1
  67. package/lib/operations/bulk_write.js.map +1 -1
  68. package/lib/operations/command.js +7 -3
  69. package/lib/operations/command.js.map +1 -1
  70. package/lib/operations/common_functions.js +1 -1
  71. package/lib/operations/common_functions.js.map +1 -1
  72. package/lib/operations/connect.js +1 -1
  73. package/lib/operations/connect.js.map +1 -1
  74. package/lib/operations/count.js +1 -1
  75. package/lib/operations/count.js.map +1 -1
  76. package/lib/operations/count_documents.js.map +1 -1
  77. package/lib/operations/create_collection.js +1 -1
  78. package/lib/operations/create_collection.js.map +1 -1
  79. package/lib/operations/delete.js +6 -6
  80. package/lib/operations/delete.js.map +1 -1
  81. package/lib/operations/distinct.js +4 -4
  82. package/lib/operations/distinct.js.map +1 -1
  83. package/lib/operations/drop.js +2 -2
  84. package/lib/operations/drop.js.map +1 -1
  85. package/lib/operations/estimated_document_count.js +2 -2
  86. package/lib/operations/estimated_document_count.js.map +1 -1
  87. package/lib/operations/eval.js.map +1 -1
  88. package/lib/operations/execute_operation.js +17 -7
  89. package/lib/operations/execute_operation.js.map +1 -1
  90. package/lib/operations/find.js +8 -8
  91. package/lib/operations/find.js.map +1 -1
  92. package/lib/operations/find_and_modify.js +7 -7
  93. package/lib/operations/find_and_modify.js.map +1 -1
  94. package/lib/operations/indexes.js +14 -14
  95. package/lib/operations/indexes.js.map +1 -1
  96. package/lib/operations/insert.js +5 -5
  97. package/lib/operations/insert.js.map +1 -1
  98. package/lib/operations/list_collections.js +12 -7
  99. package/lib/operations/list_collections.js.map +1 -1
  100. package/lib/operations/list_databases.js +1 -1
  101. package/lib/operations/list_databases.js.map +1 -1
  102. package/lib/operations/map_reduce.js +6 -6
  103. package/lib/operations/map_reduce.js.map +1 -1
  104. package/lib/operations/operation.js +2 -1
  105. package/lib/operations/operation.js.map +1 -1
  106. package/lib/operations/remove_user.js +1 -1
  107. package/lib/operations/remove_user.js.map +1 -1
  108. package/lib/operations/rename.js +2 -2
  109. package/lib/operations/rename.js.map +1 -1
  110. package/lib/operations/set_profiling_level.js +1 -1
  111. package/lib/operations/set_profiling_level.js.map +1 -1
  112. package/lib/operations/stats.js +2 -2
  113. package/lib/operations/stats.js.map +1 -1
  114. package/lib/operations/update.js +12 -12
  115. package/lib/operations/update.js.map +1 -1
  116. package/lib/sdam/monitor.js +14 -14
  117. package/lib/sdam/monitor.js.map +1 -1
  118. package/lib/sdam/server.js +19 -12
  119. package/lib/sdam/server.js.map +1 -1
  120. package/lib/sdam/server_description.js +3 -3
  121. package/lib/sdam/server_description.js.map +1 -1
  122. package/lib/sdam/server_selection.js +20 -1
  123. package/lib/sdam/server_selection.js.map +1 -1
  124. package/lib/sdam/srv_polling.js +9 -9
  125. package/lib/sdam/srv_polling.js.map +1 -1
  126. package/lib/sdam/topology.js +29 -21
  127. package/lib/sdam/topology.js.map +1 -1
  128. package/lib/sdam/topology_description.js +34 -12
  129. package/lib/sdam/topology_description.js.map +1 -1
  130. package/lib/sessions.js +19 -19
  131. package/lib/sessions.js.map +1 -1
  132. package/lib/transactions.js.map +1 -1
  133. package/lib/utils.js +53 -46
  134. package/lib/utils.js.map +1 -1
  135. package/mongodb.d.ts +97 -50
  136. package/mongodb.ts34.d.ts +96 -50
  137. package/package.json +44 -47
  138. package/src/bulk/common.ts +56 -35
  139. package/src/change_stream.ts +8 -6
  140. package/src/cmap/auth/mongo_credentials.ts +14 -3
  141. package/src/cmap/auth/mongodb_aws.ts +32 -31
  142. package/src/cmap/command_monitoring_events.ts +1 -1
  143. package/src/cmap/connection.ts +1 -0
  144. package/src/cmap/wire_protocol/constants.ts +4 -4
  145. package/src/collection.ts +32 -24
  146. package/src/connection_string.ts +103 -52
  147. package/src/cursor/abstract_cursor.ts +6 -4
  148. package/src/cursor/aggregation_cursor.ts +3 -3
  149. package/src/cursor/find_cursor.ts +1 -1
  150. package/src/db.ts +5 -6
  151. package/src/deps.ts +56 -19
  152. package/src/gridfs/download.ts +1 -1
  153. package/src/gridfs/upload.ts +11 -7
  154. package/src/index.ts +12 -1
  155. package/src/mongo_client.ts +18 -11
  156. package/src/mongo_types.ts +10 -13
  157. package/src/operations/aggregate.ts +1 -2
  158. package/src/operations/command.ts +5 -0
  159. package/src/operations/count.ts +1 -1
  160. package/src/operations/count_documents.ts +1 -1
  161. package/src/operations/create_collection.ts +1 -1
  162. package/src/operations/eval.ts +1 -1
  163. package/src/operations/execute_operation.ts +13 -2
  164. package/src/operations/indexes.ts +2 -2
  165. package/src/operations/list_collections.ts +12 -4
  166. package/src/operations/list_databases.ts +6 -1
  167. package/src/operations/operation.ts +3 -0
  168. package/src/sdam/server.ts +8 -0
  169. package/src/sdam/server_selection.ts +25 -0
  170. package/src/sdam/srv_polling.ts +12 -11
  171. package/src/sdam/topology.ts +27 -10
  172. package/src/sdam/topology_description.ts +35 -11
  173. package/src/transactions.ts +2 -2
  174. package/src/utils.ts +67 -56
package/mongodb.ts34.d.ts CHANGED
@@ -25,6 +25,7 @@ import { Readable } from 'stream';
25
25
  import { serialize as serialize_2 } from 'bson';
26
26
  import { SerializeOptions } from 'bson';
27
27
  import { Socket } from 'net';
28
+ import { SrvRecord } from 'dns';
28
29
  import { TcpNetConnectOpts } from 'net';
29
30
  import { Timestamp } from 'bson';
30
31
  import { TLSSocket } from 'tls';
@@ -391,8 +392,11 @@ export declare class AggregationCursor<TSchema = Document> extends AbstractCurso
391
392
  limit($limit: number): this;
392
393
  /** Add a match stage to the aggregation pipeline */
393
394
  match($match: Document): this;
394
- /** Add a out stage to the aggregation pipeline */
395
- out($out: number): this;
395
+ /** Add an out stage to the aggregation pipeline */
396
+ out($out: {
397
+ db: string;
398
+ coll: string;
399
+ } | string): this;
396
400
  /**
397
401
  * Add a project stage to the aggregation pipeline
398
402
  *
@@ -502,6 +506,13 @@ export declare const AuthMechanism: Readonly<{
502
506
  /** @public */
503
507
  export declare type AuthMechanism = typeof AuthMechanism[keyof typeof AuthMechanism];
504
508
  /** @public */
509
+ export declare interface AuthMechanismProperties extends Document {
510
+ SERVICE_NAME?: string;
511
+ SERVICE_REALM?: string;
512
+ CANONICALIZE_HOST_NAME?: boolean;
513
+ AWS_SESSION_TOKEN?: string;
514
+ }
515
+ /** @public */
505
516
  export declare interface AutoEncrypter {
506
517
  new (client: MongoClient, options: AutoEncryptionOptions): AutoEncrypter;
507
518
  init(cb: Callback): void;
@@ -736,8 +747,10 @@ export declare abstract class BulkOperationBase {
736
747
  readonly bsonOptions: BSONSerializeOptions;
737
748
  readonly writeConcern: WriteConcern | undefined;
738
749
  readonly batches: Batch[];
739
- /** An internal helper method. Do not invoke directly. Will be going away in the future */
740
- execute(options?: BulkWriteOptions, callback?: Callback<BulkWriteResult>): Promise<BulkWriteResult> | void;
750
+ execute(options?: BulkWriteOptions): Promise<BulkWriteResult>;
751
+ execute(callback: Callback<BulkWriteResult>): void;
752
+ execute(options: BulkWriteOptions | undefined, callback: Callback<BulkWriteResult>): void;
753
+ execute(options?: BulkWriteOptions | Callback<BulkWriteResult>, callback?: Callback<BulkWriteResult>): Promise<BulkWriteResult> | void;
741
754
  /* Excluded from this release type: handleWriteError */
742
755
  abstract addToOperationsList(batchType: BatchType, document: Document | UpdateStatement | DeleteStatement): this;
743
756
  }
@@ -761,6 +774,7 @@ export declare interface BulkWriteOperationError {
761
774
  index: number;
762
775
  code: number;
763
776
  errmsg: string;
777
+ errInfo: Document;
764
778
  op: Document | UpdateStatement | DeleteStatement;
765
779
  }
766
780
  /** @public */
@@ -849,7 +863,7 @@ export declare class CancellationToken extends TypedEventEmitter<{
849
863
  * Creates a new Change Stream instance. Normally created using {@link Collection#watch|Collection.watch()}.
850
864
  * @public
851
865
  */
852
- export declare class ChangeStream<TSchema extends Document = Document> extends TypedEventEmitter<ChangeStreamEvents> {
866
+ export declare class ChangeStream<TSchema extends Document = Document> extends TypedEventEmitter<ChangeStreamEvents<TSchema>> {
853
867
  pipeline: Document[];
854
868
  options: ChangeStreamOptions;
855
869
  parent: MongoClient | Db | Collection;
@@ -963,14 +977,14 @@ export declare interface ChangeStreamDocument<TSchema extends Document = Documen
963
977
  fullDocument?: TSchema;
964
978
  }
965
979
  /** @public */
966
- export declare type ChangeStreamEvents = {
980
+ export declare type ChangeStreamEvents<TSchema extends Document = Document> = {
967
981
  resumeTokenChanged(token: ResumeToken): void;
968
- init(response: Document): void;
969
- more(response?: Document | undefined): void;
982
+ init(response: TSchema): void;
983
+ more(response?: TSchema | undefined): void;
970
984
  response(): void;
971
985
  end(): void;
972
986
  error(error: Error): void;
973
- change(change: ChangeStreamDocument): void;
987
+ change(change: ChangeStreamDocument<TSchema>): void;
974
988
  } & AbstractCursorEvents;
975
989
  /**
976
990
  * Options that can be passed to a ChangeStream. Note that startAfter, resumeAfter, and startAtOperationTime are all mutually exclusive, and the server will error if more than one is specified.
@@ -1370,12 +1384,12 @@ export declare class Collection<TSchema extends Document = Document> {
1370
1384
  * @param options - Optional settings for the command
1371
1385
  * @param callback - An optional callback, a Promise will be returned if none is provided
1372
1386
  */
1373
- findOne(): Promise<TSchema | null>;
1374
- findOne(callback: Callback<TSchema | null>): void;
1375
- findOne(filter: Filter<TSchema>): Promise<TSchema | null>;
1376
- findOne(filter: Filter<TSchema>, callback: Callback<TSchema | null>): void;
1377
- findOne(filter: Filter<TSchema>, options: FindOptions): Promise<TSchema | null>;
1378
- findOne(filter: Filter<TSchema>, options: FindOptions, callback: Callback<TSchema | null>): void;
1387
+ findOne(): Promise<WithId<TSchema> | null>;
1388
+ findOne(callback: Callback<WithId<TSchema> | null>): void;
1389
+ findOne(filter: Filter<TSchema>): Promise<WithId<TSchema> | null>;
1390
+ findOne(filter: Filter<TSchema>, callback: Callback<WithId<TSchema> | null>): void;
1391
+ findOne(filter: Filter<TSchema>, options: FindOptions): Promise<WithId<TSchema> | null>;
1392
+ findOne(filter: Filter<TSchema>, options: FindOptions, callback: Callback<WithId<TSchema> | null>): void;
1379
1393
  findOne<T = TSchema>(): Promise<T | null>;
1380
1394
  findOne<T = TSchema>(callback: Callback<T | null>): void;
1381
1395
  findOne<T = TSchema>(filter: Filter<TSchema>): Promise<T | null>;
@@ -1386,9 +1400,9 @@ export declare class Collection<TSchema extends Document = Document> {
1386
1400
  *
1387
1401
  * @param filter - The filter predicate. If unspecified, then all documents in the collection will match the predicate
1388
1402
  */
1389
- find(): FindCursor<TSchema>;
1390
- find(filter: Filter<TSchema>, options?: FindOptions): FindCursor<TSchema>;
1391
- find<T>(filter: Filter<TSchema>, options?: FindOptions): FindCursor<T>;
1403
+ find(): FindCursor<WithId<TSchema>>;
1404
+ find(filter: Filter<WithId<TSchema>>, options?: FindOptions): FindCursor<WithId<TSchema>>;
1405
+ find<T>(filter: Filter<WithId<TSchema>>, options?: FindOptions): FindCursor<T>;
1392
1406
  /**
1393
1407
  * Returns the options of the collection.
1394
1408
  *
@@ -1595,10 +1609,10 @@ export declare class Collection<TSchema extends Document = Document> {
1595
1609
  * @param options - Optional settings for the command
1596
1610
  * @param callback - An optional callback, a Promise will be returned if none is provided
1597
1611
  */
1598
- indexes(): Promise<Document>;
1599
- indexes(callback: Callback<Document>): void;
1600
- indexes(options: IndexInformationOptions): Promise<Document>;
1601
- indexes(options: IndexInformationOptions, callback: Callback<Document>): void;
1612
+ indexes(): Promise<Document[]>;
1613
+ indexes(callback: Callback<Document[]>): void;
1614
+ indexes(options: IndexInformationOptions): Promise<Document[]>;
1615
+ indexes(options: IndexInformationOptions, callback: Callback<Document[]>): void;
1602
1616
  /**
1603
1617
  * Get all the collection statistics.
1604
1618
  *
@@ -1650,7 +1664,7 @@ export declare class Collection<TSchema extends Document = Document> {
1650
1664
  * @param pipeline - An array of aggregation pipelines to execute
1651
1665
  * @param options - Optional settings for the command
1652
1666
  */
1653
- aggregate<T = TSchema>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
1667
+ aggregate<T = Document>(pipeline?: Document[], options?: AggregateOptions): AggregationCursor<T>;
1654
1668
  /**
1655
1669
  * Create a new Change Stream, watching for new changes (insertions, updates, replacements, deletions, and invalidations) in this collection.
1656
1670
  *
@@ -1662,6 +1676,7 @@ export declare class Collection<TSchema extends Document = Document> {
1662
1676
  /**
1663
1677
  * Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.
1664
1678
  *
1679
+ * @deprecated collection.mapReduce is deprecated. Use the aggregation pipeline instead. Visit https://docs.mongodb.com/manual/reference/map-reduce-to-aggregation-pipeline for more information on how to translate map-reduce operations to the aggregation pipeline.
1665
1680
  * @param map - The mapping function.
1666
1681
  * @param reduce - The reduce function.
1667
1682
  * @param options - Optional settings for the command
@@ -2214,10 +2229,9 @@ export declare class Db {
2214
2229
  * @param options - Optional settings for the command
2215
2230
  * @param callback - An optional callback, a Promise will be returned if none is provided
2216
2231
  */
2217
- createCollection<TSchema extends Document = Document>(name: string): Promise<Collection<TSchema>>;
2232
+ createCollection<TSchema extends Document = Document>(name: string, options?: CreateCollectionOptions): Promise<Collection<TSchema>>;
2218
2233
  createCollection<TSchema extends Document = Document>(name: string, callback: Callback<Collection<TSchema>>): void;
2219
- createCollection<TSchema extends Document = Document>(name: string, options: CreateCollectionOptions): Promise<Collection<TSchema>>;
2220
- createCollection<TSchema extends Document = Document>(name: string, options: CreateCollectionOptions, callback: Callback<Collection<TSchema>>): void;
2234
+ createCollection<TSchema extends Document = Document>(name: string, options: CreateCollectionOptions | undefined, callback: Callback<Collection<TSchema>>): void;
2221
2235
  /**
2222
2236
  * Execute a command
2223
2237
  *
@@ -2982,7 +2996,7 @@ export declare interface GridFSBucketOptions extends WriteConcernOptions {
2982
2996
  * Do not instantiate this class directly. Use `openDownloadStream()` instead.
2983
2997
  * @public
2984
2998
  */
2985
- export declare class GridFSBucketReadStream extends Readable {
2999
+ export declare class GridFSBucketReadStream extends Readable implements NodeJS.ReadableStream {
2986
3000
  /* Excluded from this release type: s */
2987
3001
  /**
2988
3002
  * An error occurred
@@ -3059,7 +3073,7 @@ export declare interface GridFSBucketReadStreamOptionsWithRevision extends GridF
3059
3073
  * Do not instantiate this class directly. Use `openUploadStream()` instead.
3060
3074
  * @public
3061
3075
  */
3062
- export declare class GridFSBucketWriteStream extends Writable {
3076
+ export declare class GridFSBucketWriteStream extends Writable implements NodeJS.WritableStream {
3063
3077
  bucket: GridFSBucket;
3064
3078
  chunks: Collection<GridFSChunk>;
3065
3079
  filename: string;
@@ -3097,10 +3111,10 @@ export declare class GridFSBucketWriteStream extends Writable {
3097
3111
  * @param callback - Function to call when the chunk was added to the buffer, or if the entire chunk was persisted to MongoDB if this chunk caused a flush.
3098
3112
  * @returns False if this write required flushing a chunk to MongoDB. True otherwise.
3099
3113
  */
3100
- write(chunk: Buffer): boolean;
3101
- write(chunk: Buffer, callback: Callback<void>): boolean;
3102
- write(chunk: Buffer, encoding: BufferEncoding | undefined): boolean;
3103
- write(chunk: Buffer, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
3114
+ write(chunk: Buffer | string): boolean;
3115
+ write(chunk: Buffer | string, callback: Callback<void>): boolean;
3116
+ write(chunk: Buffer | string, encoding: BufferEncoding | undefined): boolean;
3117
+ write(chunk: Buffer | string, encoding: BufferEncoding | undefined, callback: Callback<void>): boolean;
3104
3118
  /**
3105
3119
  * Places this write stream into an aborted state (all future writes fail)
3106
3120
  * and deletes all chunks that have already been written.
@@ -3170,11 +3184,13 @@ export declare class HostAddress {
3170
3184
  socketPath: string | undefined;
3171
3185
  isIPv6: boolean | undefined;
3172
3186
  constructor(hostString: string);
3187
+ inspect(): string;
3173
3188
  /**
3174
3189
  * @param ipv6Brackets - optionally request ipv6 bracket notation required for connection strings
3175
3190
  */
3176
3191
  toString(ipv6Brackets?: boolean): string;
3177
3192
  static fromString(s: string): HostAddress;
3193
+ static fromSrvRecord({ name, port }: SrvRecord): HostAddress;
3178
3194
  }
3179
3195
  /** @public */
3180
3196
  export declare interface IndexDescription extends Pick<CreateIndexesOptions, 'background' | 'unique' | 'partialFilterExpression' | 'sparse' | 'hidden' | 'expireAfterSeconds' | 'storageEngine' | 'version' | 'weights' | 'default_language' | 'language_override' | 'textIndexVersion' | '2dsphereIndexVersion' | 'bits' | 'min' | 'max' | 'bucketSize' | 'wildcardProjection'> {
@@ -3355,6 +3371,8 @@ export declare class ListCollectionsCursor<T extends Pick<CollectionInfo, 'name'
3355
3371
  export declare interface ListCollectionsOptions extends CommandOperationOptions {
3356
3372
  /** Since 4.0: If true, will only return the collection name in the response, and will omit additional info */
3357
3373
  nameOnly?: boolean;
3374
+ /** Since 4.0: If true and nameOnly is true, allows a user without the required privilege (i.e. listCollections action on the database) to run the command when access control is enforced. */
3375
+ authorizedCollections?: boolean;
3358
3376
  /** The batchSize for the returned command cursor or if pre 2.8 the systems batch collection */
3359
3377
  batchSize?: number;
3360
3378
  }
@@ -3368,7 +3386,16 @@ export declare interface ListDatabasesOptions extends CommandOperationOptions {
3368
3386
  authorizedDatabases?: boolean;
3369
3387
  }
3370
3388
  /** @public */
3371
- export declare type ListDatabasesResult = string[] | Document[];
3389
+ export declare interface ListDatabasesResult {
3390
+ databases: ({
3391
+ name: string;
3392
+ sizeOnDisk?: number;
3393
+ empty?: boolean;
3394
+ } & Document)[];
3395
+ totalSize?: number;
3396
+ totalSizeMb?: number;
3397
+ ok: 1 | 0;
3398
+ }
3372
3399
  /** @public */
3373
3400
  export declare class ListIndexesCursor extends AbstractCursor {
3374
3401
  parent: Collection;
@@ -3738,7 +3765,7 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3738
3765
  ssl?: boolean;
3739
3766
  /** Specifies the location of a local TLS Certificate */
3740
3767
  tlsCertificateFile?: string;
3741
- /** Specifies the location of a local .pem file that contains either the clients TLS/SSL certificate or the clients TLS/SSL certificate and key. */
3768
+ /** Specifies the location of a local .pem file that contains either the client's TLS/SSL certificate and key or only the client's TLS/SSL key when tlsCertificateFile is used to provide the certificate. */
3742
3769
  tlsCertificateKeyFile?: string;
3743
3770
  /** Specifies the password to de-crypt the tlsCertificateKeyFile. */
3744
3771
  tlsCertificateKeyFilePassword?: string;
@@ -3754,10 +3781,20 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3754
3781
  connectTimeoutMS?: number;
3755
3782
  /** The time in milliseconds to attempt a send or receive on a socket before the attempt times out. */
3756
3783
  socketTimeoutMS?: number;
3757
- /** Comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */
3758
- compressors?: CompressorName[];
3784
+ /** An array or comma-delimited string of compressors to enable network compression for communication between this client and a mongod/mongos instance. */
3785
+ compressors?: CompressorName[] | string;
3759
3786
  /** An integer that specifies the compression level if using zlib for network compression. */
3760
3787
  zlibCompressionLevel?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | undefined;
3788
+ /** The maximum number of hosts to connect to when using an srv connection string, a setting of `0` means unlimited hosts */
3789
+ srvMaxHosts?: number;
3790
+ /**
3791
+ * Modifies the srv URI to look like:
3792
+ *
3793
+ * `_{srvServiceName}._tcp.{hostname}.{domainname}`
3794
+ *
3795
+ * Querying this DNS URI is expected to respond with SRV records
3796
+ */
3797
+ srvServiceName?: string;
3761
3798
  /** The maximum number of connections in the connection pool. */
3762
3799
  maxPoolSize?: number;
3763
3800
  /** The minimum number of connections in the connection pool. */
@@ -3783,12 +3820,7 @@ export declare interface MongoClientOptions extends BSONSerializeOptions, Suppor
3783
3820
  /** Specify the authentication mechanism that MongoDB will use to authenticate the connection. */
3784
3821
  authMechanism?: AuthMechanism;
3785
3822
  /** Specify properties for the specified authMechanism as a comma-separated list of colon-separated key-value pairs. */
3786
- authMechanismProperties?: {
3787
- SERVICE_NAME?: string;
3788
- CANONICALIZE_HOST_NAME?: boolean;
3789
- SERVICE_REALM?: string;
3790
- [key: string]: any;
3791
- };
3823
+ authMechanismProperties?: AuthMechanismProperties;
3792
3824
  /** The size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances. */
3793
3825
  localThresholdMS?: number;
3794
3826
  /** Specifies how long (in milliseconds) to block for server selection before throwing an exception. */
@@ -3893,7 +3925,7 @@ export declare class MongoCredentials {
3893
3925
  /** The method used to authenticate */
3894
3926
  readonly mechanism: AuthMechanism;
3895
3927
  /** Special properties used by some types of auth mechanisms */
3896
- readonly mechanismProperties: Document;
3928
+ readonly mechanismProperties: AuthMechanismProperties;
3897
3929
  constructor(options: MongoCredentialsOptions);
3898
3930
  /** Determines if two MongoCredentials objects are equivalent */
3899
3931
  equals(other: MongoCredentials): boolean;
@@ -3914,7 +3946,7 @@ export declare interface MongoCredentialsOptions {
3914
3946
  source: string;
3915
3947
  db?: string;
3916
3948
  mechanism?: AuthMechanism;
3917
- mechanismProperties: Document;
3949
+ mechanismProperties: AuthMechanismProperties;
3918
3950
  }
3919
3951
  /**
3920
3952
  * An error thrown when an attempt is made to read from a cursor that has been exhausted
@@ -4121,7 +4153,7 @@ export declare class MongoNotConnectedError extends MongoAPIError {
4121
4153
  * Mongo Client Options
4122
4154
  * @public
4123
4155
  */
4124
- export declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEncryption' | 'compressors' | 'connectTimeoutMS' | 'directConnection' | 'driverInfo' | 'forceServerObjectId' | 'minHeartbeatFrequencyMS' | 'heartbeatFrequencyMS' | 'keepAlive' | 'keepAliveInitialDelay' | 'localThresholdMS' | 'logger' | 'maxIdleTimeMS' | 'maxPoolSize' | 'minPoolSize' | 'monitorCommands' | 'noDelay' | 'pkFactory' | 'promiseLibrary' | 'raw' | 'replicaSet' | 'retryReads' | 'retryWrites' | 'serverSelectionTimeoutMS' | 'socketTimeoutMS' | 'tlsAllowInvalidCertificates' | 'tlsAllowInvalidHostnames' | 'tlsInsecure' | 'waitQueueTimeoutMS' | 'zlibCompressionLevel'>>, SupportedNodeConnectionOptions {
4156
+ export declare interface MongoOptions extends Required<Pick<MongoClientOptions, 'autoEncryption' | 'connectTimeoutMS' | 'directConnection' | 'driverInfo' | 'forceServerObjectId' | 'minHeartbeatFrequencyMS' | 'heartbeatFrequencyMS' | 'keepAlive' | 'keepAliveInitialDelay' | 'localThresholdMS' | 'logger' | 'maxIdleTimeMS' | 'maxPoolSize' | 'minPoolSize' | 'monitorCommands' | 'noDelay' | 'pkFactory' | 'promiseLibrary' | 'raw' | 'replicaSet' | 'retryReads' | 'retryWrites' | 'serverSelectionTimeoutMS' | 'socketTimeoutMS' | 'srvMaxHosts' | 'srvServiceName' | 'tlsAllowInvalidCertificates' | 'tlsAllowInvalidHostnames' | 'tlsInsecure' | 'waitQueueTimeoutMS' | 'zlibCompressionLevel'>>, SupportedNodeConnectionOptions {
4125
4157
  hosts: HostAddress[];
4126
4158
  srvHost?: string;
4127
4159
  credentials?: MongoCredentials;
@@ -4129,6 +4161,7 @@ export declare interface MongoOptions extends Required<Pick<MongoClientOptions,
4129
4161
  readConcern: ReadConcern;
4130
4162
  loadBalanced: boolean;
4131
4163
  serverApi: ServerApi;
4164
+ compressors: CompressorName[];
4132
4165
  writeConcern: WriteConcern;
4133
4166
  dbName: string;
4134
4167
  metadata: ClientMetadata;
@@ -4287,6 +4320,11 @@ export declare type NotAcceptedFields<TSchema, FieldType> = {
4287
4320
  };
4288
4321
  /** @public */
4289
4322
  export declare type NumericType = IntegerType | Decimal128 | Double;
4323
+ /**
4324
+ * @public
4325
+ * @deprecated Please use `ObjectId`
4326
+ */
4327
+ export declare const ObjectID: typeof ObjectId;
4290
4328
  export { ObjectId };
4291
4329
  /** @public */
4292
4330
  export declare type OneOrMore<T> = T | ReadonlyArray<T>;
@@ -4300,6 +4338,8 @@ export declare interface OperationOptions extends BSONSerializeOptions {
4300
4338
  willRetryWrites?: boolean;
4301
4339
  /** The preferred read preference (ReadPreference.primary, ReadPreference.primary_preferred, ReadPreference.secondary, ReadPreference.secondary_preferred, ReadPreference.nearest). */
4302
4340
  readPreference?: ReadPreferenceLike;
4341
+ /* Excluded from this release type: bypassPinningCheck */
4342
+ omitReadPreference?: boolean;
4303
4343
  }
4304
4344
  /* Excluded from this release type: OperationParent */
4305
4345
  /**
@@ -4320,11 +4360,13 @@ export declare type OperationTime = Timestamp;
4320
4360
  * `TSchema['_id'] extends ObjectId` which translated to "Is the _id property ObjectId?"
4321
4361
  * we instead ask "Does ObjectId look like (have the same shape) as the _id?"
4322
4362
  */
4323
- export declare type OptionalId<TSchema extends {
4363
+ export declare type OptionalId<TSchema> = TSchema extends {
4324
4364
  _id?: any;
4325
- }> = ObjectId extends TSchema['_id'] ? EnhancedOmit<TSchema, '_id'> & {
4365
+ } ? ObjectId extends TSchema['_id'] ? EnhancedOmit<TSchema, '_id'> & {
4326
4366
  _id?: InferIdType<TSchema>;
4327
- } : WithId<TSchema>;
4367
+ } : WithId<TSchema> : EnhancedOmit<TSchema, '_id'> & {
4368
+ _id?: InferIdType<TSchema>;
4369
+ };
4328
4370
  /** @public */
4329
4371
  export declare class OrderedBulkOperation extends BulkOperationBase {
4330
4372
  constructor(collection: Collection, options: BulkWriteOptions);
@@ -4915,7 +4957,7 @@ export declare type TagSet = {
4915
4957
  export declare interface TimeSeriesCollectionOptions extends Document {
4916
4958
  timeField: string;
4917
4959
  metaField?: string;
4918
- granularity?: string;
4960
+ granularity?: 'seconds' | 'minutes' | 'hours' | string;
4919
4961
  }
4920
4962
  export { Timestamp };
4921
4963
  /* Excluded from this release type: Topology */
@@ -5004,6 +5046,8 @@ export declare class TopologyOpeningEvent {
5004
5046
  }
5005
5047
  /** @public */
5006
5048
  export declare interface TopologyOptions extends BSONSerializeOptions, ServerOptions {
5049
+ srvMaxHosts: number;
5050
+ srvServiceName: string;
5007
5051
  hosts: HostAddress[];
5008
5052
  retryWrites: boolean;
5009
5053
  retryReads: boolean;
@@ -5067,7 +5111,7 @@ export declare class Transaction {
5067
5111
  */
5068
5112
  export declare interface TransactionOptions extends CommandOperationOptions {
5069
5113
  /** A default read concern for commands in this transaction */
5070
- readConcern?: ReadConcern;
5114
+ readConcern?: ReadConcernLike;
5071
5115
  /** A default writeConcern for commands in this transaction */
5072
5116
  writeConcern?: WriteConcern;
5073
5117
  /** A default read preference for commands in this transaction */
@@ -5476,6 +5520,8 @@ export declare class WriteError {
5476
5520
  readonly index: number;
5477
5521
  /*WriteError message. */
5478
5522
  readonly errmsg: string | undefined;
5523
+ /*WriteError details. */
5524
+ readonly errInfo: Document | undefined;
5479
5525
  /** Returns the underlying operation that caused the error */
5480
5526
  getOperation(): Document;
5481
5527
  toJSON(): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
4
4
  "description": "The official MongoDB driver for Node.js",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -32,62 +32,55 @@
32
32
  "email": "dbx-node@mongodb.com"
33
33
  },
34
34
  "dependencies": {
35
- "bson": "^4.5.1",
36
- "denque": "^1.5.0",
37
- "mongodb-connection-string-url": "^2.0.0"
35
+ "bson": "^4.5.4",
36
+ "denque": "^2.0.1",
37
+ "mongodb-connection-string-url": "^2.2.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@istanbuljs/nyc-config-typescript": "^1.0.1",
41
- "@microsoft/api-extractor": "^7.16.1",
41
+ "@microsoft/api-extractor": "^7.18.14",
42
42
  "@microsoft/tsdoc-config": "^0.15.2",
43
- "@types/aws4": "^1.5.1",
44
- "@types/chai": "^4.2.14",
43
+ "@types/chai": "^4.2.22",
45
44
  "@types/chai-subset": "^1.3.3",
46
- "@types/kerberos": "^1.1.0",
47
- "@types/mocha": "^8.2.0",
48
- "@types/node": "^15.3.1",
49
- "@types/saslprep": "^1.0.0",
50
- "@types/semver": "^7.3.4",
45
+ "@types/kerberos": "^1.1.1",
46
+ "@types/mocha": "^9.0.0",
47
+ "@types/node": "^16.10.3",
48
+ "@types/saslprep": "^1.0.1",
49
+ "@types/semver": "^7.3.8",
50
+ "@types/sinon": "^10.0.6",
51
51
  "@types/whatwg-url": "^8.2.1",
52
- "@typescript-eslint/eslint-plugin": "^4.19.0",
53
- "@typescript-eslint/parser": "^4.19.0",
52
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
53
+ "@typescript-eslint/parser": "^4.33.0",
54
54
  "bluebird": "^3.7.2",
55
- "chai": "^4.2.0",
55
+ "chai": "^4.3.4",
56
56
  "chai-subset": "^1.6.0",
57
- "chalk": "^4.1.0",
57
+ "chalk": "^4.1.2",
58
58
  "co": "4.6.0",
59
- "coveralls": "^3.0.11",
60
59
  "downlevel-dts": "^0.7.0",
61
- "eslint": "^7.26.0",
62
- "eslint-config-prettier": "^6.11.0",
63
- "eslint-plugin-jsdoc": "^30.7.8",
64
- "eslint-plugin-prettier": "^3.1.3",
60
+ "eslint": "^7.32.0",
61
+ "eslint-config-prettier": "^8.3.0",
62
+ "eslint-plugin-prettier": "^4.0.0",
65
63
  "eslint-plugin-tsdoc": "^0.2.14",
66
- "js-yaml": "^3.14.0",
67
- "jsdoc": "^3.6.4",
64
+ "js-yaml": "^4.1.0",
68
65
  "lodash.camelcase": "^4.3.0",
69
- "madge": "^4.0.2",
70
- "mocha": "^7.1.1",
71
- "mocha-sinon": "^2.1.0",
66
+ "mocha": "^9.1.2",
67
+ "mocha-sinon": "^2.1.2",
72
68
  "mongodb-mock-server": "^2.0.1",
73
69
  "nyc": "^15.1.0",
74
- "prettier": "2.1.1",
70
+ "prettier": "^2.4.1",
75
71
  "rimraf": "^3.0.2",
76
- "semver": "^5.5.0",
77
- "sinon": "^4.3.0",
78
- "sinon-chai": "^3.2.0",
79
- "source-map-support": "^0.5.19",
72
+ "semver": "^7.3.5",
73
+ "sinon": "^12.0.1",
74
+ "sinon-chai": "^3.7.0",
75
+ "source-map-support": "^0.5.20",
80
76
  "standard-version": "^9.3.1",
81
- "through2": "^3.0.1",
82
- "ts-node": "^10.0.0",
77
+ "ts-node": "^10.2.1",
83
78
  "tsd": "^0.17.0",
84
- "typedoc": "^0.21.0",
85
- "typescript": "^4.3.4",
79
+ "typedoc": "^0.22.5",
80
+ "typescript": "4.4.3",
86
81
  "typescript-cached-transpile": "^0.0.6",
87
- "worker-farm": "^1.5.0",
88
- "wtfnode": "^0.8.2",
89
82
  "xml2js": "^0.4.23",
90
- "yargs": "^14.2.0"
83
+ "yargs": "^17.2.1"
91
84
  },
92
85
  "license": "Apache-2.0",
93
86
  "engines": {
@@ -98,31 +91,35 @@
98
91
  },
99
92
  "homepage": "https://github.com/mongodb/node-mongodb-native",
100
93
  "optionalDependencies": {
101
- "saslprep": "^1.0.0"
94
+ "saslprep": "^1.0.3"
102
95
  },
103
96
  "scripts": {
104
97
  "build:evergreen": "node .evergreen/generate_evergreen_tasks.js",
105
- "build:ts": "rimraf lib && tsc",
98
+ "build:ts": "rimraf lib && ./node_modules/typescript/bin/tsc",
106
99
  "build:dts": "npm run build:ts && api-extractor run && rimraf 'lib/**/*.d.ts*' && downlevel-dts mongodb.d.ts mongodb.ts34.d.ts",
107
100
  "build:docs": "typedoc",
108
101
  "check:bench": "node test/benchmarks/driverBench",
109
- "check:coverage": "nyc npm run check:test",
102
+ "check:coverage": "nyc npm run test:all",
110
103
  "check:lint": "npm run build:dts && npm run check:dts && npm run check:eslint && npm run check:tsd",
111
104
  "check:eslint": "eslint -v && eslint --max-warnings=0 --ext '.js,.ts' src test",
112
105
  "check:tsd": "tsd --version && tsd",
113
- "check:dts": "tsc --noEmit mongodb.d.ts && tsd",
114
- "check:test": "mocha --recursive test/functional test/unit",
115
- "check:ts": "tsc -v && tsc --noEmit",
106
+ "check:dts": "./node_modules/typescript/bin/tsc --noEmit mongodb.d.ts && tsd",
107
+ "check:test": "mocha --file test/tools/runner --recursive test/functional test/integration",
108
+ "check:unit": "mocha --recursive test/unit/",
109
+ "check:ts": "./node_modules/typescript/bin/tsc -v && ./node_modules/typescript/bin/tsc --noEmit",
116
110
  "check:atlas": "mocha --config \"test/manual/mocharc.json\" test/manual/atlas_connectivity.test.js",
117
- "check:adl": "mocha test/manual/data_lake.test.js",
111
+ "check:adl": "mocha --file test/tools/runner test/manual/data_lake.test.js",
112
+ "check:aws": "mocha --file test/tools/runner test/functional/mongodb_aws.test.js",
118
113
  "check:ocsp": "mocha --config \"test/manual/mocharc.json\" test/manual/ocsp_support.test.js",
119
114
  "check:kerberos": "mocha --config \"test/manual/mocharc.json\" test/manual/kerberos.test.js",
120
115
  "check:tls": "mocha --config \"test/manual/mocharc.json\" test/manual/tls_support.test.js",
121
116
  "check:ldap": "mocha --config \"test/manual/mocharc.json\" test/manual/ldap.test.js",
122
- "check:csfle": "mocha test/functional/client_side_encryption",
117
+ "check:csfle": "mocha --file test/tools/runner test/functional/client_side_encryption",
118
+ "check:snappy": "mocha --file test/tools/runner test/functional/unit_snappy.test.js",
123
119
  "prepare": "node etc/prepare.js",
124
120
  "release": "standard-version -i HISTORY.md",
125
- "test": "npm run check:lint && npm run check:test"
121
+ "test": "npm run check:lint && npm run test:all",
122
+ "test:all": "npm run check:unit && npm run check:test"
126
123
  },
127
124
  "tsd": {
128
125
  "directory": "test/types",