@@ -17,12 +17,7 @@ module.exports = function(url, options, callback) {
17
17
}
18
18
19
19
if ( result . protocol === 'mongodb+srv:' ) {
20
- if ( options ) {
21
- // TODO let the options passed in override
22
- if ( options . ssl && options . ssl !== true ) {
23
- options . ssl = true ;
24
- }
25
- }
20
+
26
21
if ( result . hostname . split ( '.' ) . length < 3 ) {
27
22
return callback ( new Error ( 'uri does not have hostname, domainname and tld' ) ) ;
28
23
}
@@ -56,15 +51,28 @@ module.exports = function(url, options, callback) {
56
51
else return `${ address . name } :${ address . port } ` ;
57
52
} ) ;
58
53
59
- let connectionString = connectionStrings . join ( ',' ) + '/?' ;
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 += '?'
60
+ // 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
+ }
60
66
61
67
dns . resolveTxt ( result . host , function ( err , record ) {
62
68
if ( err && err . code !== 'ENODATA' ) return callback ( err ) ;
63
69
if ( err && err . code === 'ENODATA' ) record = null ;
70
+
64
71
if ( record ) {
65
72
if ( record . length > 1 ) {
66
73
return callback ( new Error ( 'multiple text records not allowed' ) ) ;
67
74
}
75
+
68
76
record = record [ 0 ] ;
69
77
if ( record . length > 1 ) record = record . join ( '' ) ;
70
78
else record = record [ 0 ] ;
@@ -73,9 +81,8 @@ module.exports = function(url, options, callback) {
73
81
return callback ( new Error ( 'text record must only set `authSource` or `replicaSet`' ) ) ;
74
82
}
75
83
76
- connectionString += record ;
84
+ connectionString += '&' + record ;
77
85
}
78
-
79
86
parseHandler ( connectionString , options , callback ) ;
80
87
} ) ;
81
88
} ) ;
0 commit comments