@@ -62,6 +62,7 @@ const URI_OPTIONS: &[&str] = &[
62
62
"maxstalenessseconds" ,
63
63
"maxpoolsize" ,
64
64
"minpoolsize" ,
65
+ "maxconnecting" ,
65
66
"readconcernlevel" ,
66
67
"readpreference" ,
67
68
"readpreferencetags" ,
@@ -491,6 +492,12 @@ pub struct ClientOptions {
491
492
#[ builder( default ) ]
492
493
pub min_pool_size : Option < u32 > ,
493
494
495
+ /// The maximum number of new connections that can be created concurrently.
496
+ ///
497
+ /// If specified, this value must be greater than 0. The default is 2.
498
+ #[ builder( default ) ]
499
+ pub max_connecting : Option < u32 > ,
500
+
494
501
/// Specifies the default read concern for operations performed on the Client. See the
495
502
/// ReadConcern type documentation for more details.
496
503
#[ builder( default ) ]
@@ -669,6 +676,8 @@ impl Serialize for ClientOptions {
669
676
670
677
minpoolsize : & ' a Option < u32 > ,
671
678
679
+ maxconnecting : & ' a Option < u32 > ,
680
+
672
681
#[ serde( flatten, serialize_with = "ReadConcern::serialize_for_client_options" ) ]
673
682
readconcern : & ' a Option < ReadConcern > ,
674
683
@@ -711,6 +720,7 @@ impl Serialize for ClientOptions {
711
720
maxidletimems : & self . max_idle_time ,
712
721
maxpoolsize : & self . max_pool_size ,
713
722
minpoolsize : & self . min_pool_size ,
723
+ maxconnecting : & self . max_connecting ,
714
724
readconcern : & self . read_concern ,
715
725
replicaset : & self . repl_set_name ,
716
726
retryreads : & self . retry_reads ,
@@ -802,6 +812,11 @@ pub struct ConnectionString {
802
812
/// The default value is 0.
803
813
pub min_pool_size : Option < u32 > ,
804
814
815
+ /// The maximum number of new connections that can be created concurrently.
816
+ ///
817
+ /// If specified, this value must be greater than 0. The default is 2.
818
+ pub max_connecting : Option < u32 > ,
819
+
805
820
/// The amount of time that a connection can remain idle in a connection pool before being
806
821
/// closed. A value of zero indicates that connections should not be closed due to being idle.
807
822
///
@@ -1285,6 +1300,7 @@ impl ClientOptions {
1285
1300
} ;
1286
1301
}
1287
1302
}
1303
+
1288
1304
Self {
1289
1305
hosts : vec ! [ ] ,
1290
1306
app_name : conn_str. app_name ,
@@ -1298,6 +1314,7 @@ impl ClientOptions {
1298
1314
max_pool_size : conn_str. max_pool_size ,
1299
1315
min_pool_size : conn_str. min_pool_size ,
1300
1316
max_idle_time : conn_str. max_idle_time ,
1317
+ max_connecting : conn_str. max_connecting ,
1301
1318
server_selection_timeout : conn_str. server_selection_timeout ,
1302
1319
compressors : conn_str. compressors ,
1303
1320
connect_timeout : conn_str. connect_timeout ,
@@ -1378,6 +1395,10 @@ impl ClientOptions {
1378
1395
return Err ( Error :: invalid_argument ( "cannot specify maxPoolSize=0" ) ) ;
1379
1396
}
1380
1397
1398
+ if let Some ( 0 ) = self . max_connecting {
1399
+ return Err ( Error :: invalid_argument ( "cannot specify maxConnecting=0" ) ) ;
1400
+ }
1401
+
1381
1402
if let Some ( SelectionCriteria :: ReadPreference ( ref rp) ) = self . selection_criteria {
1382
1403
if let Some ( max_staleness) = rp. max_staleness ( ) {
1383
1404
verify_max_staleness (
@@ -2028,6 +2049,9 @@ impl ConnectionString {
2028
2049
k @ "minpoolsize" => {
2029
2050
self . min_pool_size = Some ( get_u32 ! ( value, k) ) ;
2030
2051
}
2052
+ k @ "maxconnecting" => {
2053
+ self . max_connecting = Some ( get_u32 ! ( value, k) ) ;
2054
+ }
2031
2055
"readconcernlevel" => {
2032
2056
self . read_concern = Some ( ReadConcernLevel :: from_str ( value) . into ( ) ) ;
2033
2057
}
0 commit comments