@@ -438,7 +438,11 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> {
438
438
options . ca ??= await fs . readFile ( options . tlsCAFile , { encoding : 'utf8' } ) ;
439
439
}
440
440
if ( typeof options . tlsCertificateKeyFile === 'string' ) {
441
- options . key ??= await fs . readFile ( options . tlsCertificateKeyFile , { encoding : 'utf8' } ) ;
441
+ if ( ! options . key || ! options . cert ) {
442
+ const contents = await fs . readFile ( options . tlsCertificateKeyFile , { encoding : 'utf8' } ) ;
443
+ options . key ??= contents ;
444
+ options . cert ??= contents ;
445
+ }
442
446
}
443
447
}
444
448
if ( typeof options . srvHost === 'string' ) {
@@ -787,6 +791,7 @@ export interface MongoOptions
787
791
* |:----------------------|:----------------------------------------------|:-------------------|
788
792
* | `ca` | `tlsCAFile` | `string` |
789
793
* | `crl` | N/A | `string` |
794
+ * | `cert` | `tlsCertificateKeyFile` | `string` |
790
795
* | `key` | `tlsCertificateKeyFile` | `string` |
791
796
* | `passphrase` | `tlsCertificateKeyFilePassword` | `string` |
792
797
* | `rejectUnauthorized` | `tlsAllowInvalidCertificates` | `boolean` |
@@ -804,9 +809,9 @@ export interface MongoOptions
804
809
*
805
810
* The files specified by the paths passed in to the `tlsCAFile` and `tlsCertificateKeyFile` fields
806
811
* are read lazily on the first call to `MongoClient.connect`. Once these files have been read and
807
- * the `ca` and `key` fields are populated, they will not be read again on subsequent calls to
808
- * `MongoClient.connect`. As a result, until the first call to `MongoClient.connect`, the `ca`
809
- * and `key` fields will be undefined.
812
+ * the `ca`, `cert` and `key` fields are populated, they will not be read again on subsequent calls to
813
+ * `MongoClient.connect`. As a result, until the first call to `MongoClient.connect`, the `ca`,
814
+ * `cert` and `key` fields will be undefined.
810
815
*/
811
816
tls : boolean ;
812
817
0 commit comments