@@ -222,6 +222,8 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
222
222
logger ?: Logger ;
223
223
/** Enable command monitoring for this client */
224
224
monitorCommands ?: boolean ;
225
+ /** Server API version */
226
+ serverApi ?: ServerApiVersion | ServerApi ;
225
227
/** Optionally enable client side auto encryption */
226
228
autoEncryption ?: AutoEncryptionOptions ;
227
229
/** Allows a wrapping driver to amend the client metadata generated by the driver to include information about the wrapping driver */
@@ -243,13 +245,13 @@ export interface MongoClientPrivate {
243
245
readConcern ?: ReadConcern ;
244
246
writeConcern ?: WriteConcern ;
245
247
readPreference : ReadPreference ;
248
+ serverApi : ServerApi ;
246
249
bsonOptions : BSONSerializeOptions ;
247
250
namespace : MongoDBNamespace ;
248
251
logger : Logger ;
249
252
}
250
253
251
254
const kOptions = Symbol ( 'options' ) ;
252
- const kServerApi = Symbol ( 'serverApi' ) ;
253
255
254
256
/**
255
257
* The **MongoClient** class is a class that allows for making Connections to MongoDB.
@@ -302,24 +304,17 @@ export class MongoClient extends EventEmitter {
302
304
*/
303
305
[ kOptions ] : MongoOptions ;
304
306
305
- /**
306
- * The MongoDB Server API version
307
- * @internal
308
- * */
309
- [ kServerApi ] : ServerApi ;
310
-
311
307
// debugging
312
308
originalUri ;
313
309
originalOptions ;
314
310
315
- constructor ( url : string , options ?: MongoClientOptions , serverApi ?: ServerApi ) {
311
+ constructor ( url : string , options ?: MongoClientOptions ) {
316
312
super ( ) ;
317
313
318
314
this . originalUri = url ;
319
315
this . originalOptions = options ;
320
316
321
317
this [ kOptions ] = parseOptions ( url , this , options ) ;
322
- this [ kServerApi ] = Object . freeze ( { version : ServerApiVersion . v1 , ...serverApi } ) ;
323
318
324
319
// The internal state
325
320
this . s = {
@@ -329,6 +324,7 @@ export class MongoClient extends EventEmitter {
329
324
readConcern : this [ kOptions ] . readConcern ,
330
325
writeConcern : this [ kOptions ] . writeConcern ,
331
326
readPreference : this [ kOptions ] . readPreference ,
327
+ serverApi : this [ kOptions ] . serverApi ,
332
328
bsonOptions : resolveBSONOptions ( this [ kOptions ] ) ,
333
329
namespace : ns ( 'admin' ) ,
334
330
logger : this [ kOptions ] . logger
@@ -339,8 +335,8 @@ export class MongoClient extends EventEmitter {
339
335
return Object . freeze ( { ...this [ kOptions ] } ) ;
340
336
}
341
337
342
- get serverApi ( ) : Readonly < ServerApi > {
343
- return this [ kServerApi ] ;
338
+ get serverApi ( ) : Readonly < ServerApi | undefined > {
339
+ return this [ kOptions ] . serverApi && Object . freeze ( { ... this [ kOptions ] . serverApi } ) ;
344
340
}
345
341
346
342
get autoEncrypter ( ) : AutoEncrypter | undefined {
@@ -652,6 +648,7 @@ export interface MongoOptions
652
648
credentials ?: MongoCredentials ;
653
649
readPreference : ReadPreference ;
654
650
readConcern : ReadConcern ;
651
+ serverApi : ServerApi ;
655
652
writeConcern : WriteConcern ;
656
653
dbName : string ;
657
654
metadata : ClientMetadata ;
0 commit comments