@@ -89,6 +89,7 @@ const URI_OPTIONS: &[&str] = &[
89
89
"waitqueuetimeoutms" ,
90
90
"wtimeoutms" ,
91
91
"zlibcompressionlevel" ,
92
+ "srvservicename" ,
92
93
] ;
93
94
94
95
/// Reserved characters as defined by [Section 2.2 of RFC-3986](https://tools.ietf.org/html/rfc3986#section-2.2).
@@ -521,6 +522,9 @@ pub struct ClientOptions {
521
522
/// By default, no default database is specified.
522
523
pub default_database : Option < String > ,
523
524
525
+ /// Overrides the default "mongodb" service name for SRV lookup in both discovery and polling
526
+ pub srv_service_name : Option < String > ,
527
+
524
528
#[ builder( setter( skip) ) ]
525
529
#[ derivative( Debug = "ignore" ) ]
526
530
pub ( crate ) socket_timeout : Option < Duration > ,
@@ -676,6 +680,8 @@ impl Serialize for ClientOptions {
676
680
loadbalanced : & ' a Option < bool > ,
677
681
678
682
srvmaxhosts : Option < i32 > ,
683
+
684
+ srvservicename : & ' a Option < String > ,
679
685
}
680
686
681
687
let client_options = ClientOptionsHelper {
@@ -709,6 +715,7 @@ impl Serialize for ClientOptions {
709
715
. map ( |v| v. try_into ( ) )
710
716
. transpose ( )
711
717
. map_err ( serde:: ser:: Error :: custom) ?,
718
+ srvservicename : & self . srv_service_name ,
712
719
} ;
713
720
714
721
client_options. serialize ( serializer)
@@ -865,6 +872,9 @@ pub struct ConnectionString {
865
872
/// Limit on the number of mongos connections that may be created for sharded topologies.
866
873
pub srv_max_hosts : Option < u32 > ,
867
874
875
+ /// Overrides the default "mongodb" service name for SRV lookup in both discovery and polling
876
+ pub srv_service_name : Option < String > ,
877
+
868
878
wait_queue_timeout : Option < Duration > ,
869
879
tls_insecure : Option < bool > ,
870
880
@@ -900,11 +910,16 @@ impl Default for HostInfo {
900
910
}
901
911
902
912
impl HostInfo {
903
- async fn resolve ( self , resolver_config : Option < ResolverConfig > ) -> Result < ResolvedHostInfo > {
913
+ async fn resolve (
914
+ self ,
915
+ resolver_config : Option < ResolverConfig > ,
916
+ srv_service_name : Option < String > ,
917
+ ) -> Result < ResolvedHostInfo > {
904
918
Ok ( match self {
905
919
Self :: HostIdentifiers ( hosts) => ResolvedHostInfo :: HostIdentifiers ( hosts) ,
906
920
Self :: DnsRecord ( hostname) => {
907
- let mut resolver = SrvResolver :: new ( resolver_config. clone ( ) ) . await ?;
921
+ let mut resolver =
922
+ SrvResolver :: new ( resolver_config. clone ( ) , srv_service_name) . await ?;
908
923
let config = resolver. resolve_client_options ( & hostname) . await ?;
909
924
ResolvedHostInfo :: DnsRecord { hostname, config }
910
925
}
@@ -1486,6 +1501,12 @@ impl ConnectionString {
1486
1501
ConnectionStringParts :: default ( )
1487
1502
} ;
1488
1503
1504
+ if conn_str. srv_service_name . is_some ( ) && !srv {
1505
+ return Err ( Error :: invalid_argument (
1506
+ "srvServiceName cannot be specified with a non-SRV URI" ,
1507
+ ) ) ;
1508
+ }
1509
+
1489
1510
if let Some ( srv_max_hosts) = conn_str. srv_max_hosts {
1490
1511
if !srv {
1491
1512
return Err ( Error :: invalid_argument (
@@ -1976,6 +1997,9 @@ impl ConnectionString {
1976
1997
k @ "srvmaxhosts" => {
1977
1998
self . srv_max_hosts = Some ( get_u32 ! ( value, k) ) ;
1978
1999
}
2000
+ "srvservicename" => {
2001
+ self . srv_service_name = Some ( value. to_string ( ) ) ;
2002
+ }
1979
2003
k @ "tls" | k @ "ssl" => {
1980
2004
let tls = get_bool ! ( value, k) ;
1981
2005
0 commit comments