@@ -52,16 +52,18 @@ module.exports = function(url, options, callback) {
52
52
} ) ;
53
53
54
54
let connectionString = connectionStrings . join ( ',' ) + '/' ;
55
-
56
- if ( ! options . ssl && ! result . search . match ( 'ssl' ) ) {
57
- // Default to SSL true
58
- connectionString += '?ssl=true' ;
59
- } else if ( ! result . search ) connectionString += '?'
55
+ let connectionStringOptions = [ ] ;
56
+
57
+ // Default to SSL true
58
+ if ( ! options . ssl && ! result . search ) {
59
+ connectionStringOptions . push ( 'ssl=true' ) ;
60
+ } else if ( ! options . ssl && result . search && ! result . search . match ( 'ssl' ) ) {
61
+ connectionStringOptions . push ( 'ssl=true' ) ;
62
+ }
63
+
60
64
// Keep original uri options
61
- if ( result . search && ! result . search . match ( 'ssl' ) ) {
62
- connectionString += result . search . replace ( '?' , '&' ) ;
63
- } else if ( result . search && result . search . match ( 'ssl' ) ) {
64
- connectionString += result . search ;
65
+ if ( result . search ) {
66
+ connectionStringOptions . push ( result . search . replace ( '?' , '' ) ) ;
65
67
}
66
68
67
69
dns . resolveTxt ( result . host , function ( err , record ) {
@@ -81,8 +83,14 @@ module.exports = function(url, options, callback) {
81
83
return callback ( new Error ( 'text record must only set `authSource` or `replicaSet`' ) ) ;
82
84
}
83
85
84
- connectionString += '&' + record ;
86
+ connectionStringOptions . push ( record ) ;
85
87
}
88
+
89
+ // Add any options to the connection string
90
+ if ( connectionStringOptions . length ) {
91
+ connectionString += `?${ connectionStringOptions . join ( '&' ) } ` ;
92
+ }
93
+
86
94
parseHandler ( connectionString , options , callback ) ;
87
95
} ) ;
88
96
} ) ;
0 commit comments