Skip to content

Commit 12abae8

Browse files
Remove hostnameMaxLen for Mongo URL (#6693)
* Make hostnameMaxLen an environment variable. In our Mongo cluster, we have 2 shards equalling 7 hosts that come in as a long comma-delimited list of host names. This hostNameMaxLen of 255 should not apply to a mongo connection string like that: mongodb://<USER>:<PASSWORD>@MYCLUSTER-shard-00-00.luszb.azure.mongodb.net:27016,MYCLUSTER-shard-00-01.luszb.azure.mongodb.net:27016,MYCLUSTER-shard-00-02.luszb.azure.mongodb.net:27016,MYCLUSTER-shard-00-03.luszb.azure.mongodb.net:27016,MYCLUSTER-shard-02-00.luszb.azure.mongodb.net:27016,MYCLUSTER-shard-02-01.luszb.azure.mongodb.net:27016,MYCLUSTER-shard-02-02.luszb.azure.mongodb.net:27016/dev?ssl=true&authSource=admin We was using the SRV mongo connection string type which is much shorter: mongodb+srv://<USER>:<PASSWORD>@MYCLUSTER-luszb.azure.mongodb.net/dev But we were finding it to be unreliable with Azure's DNS. We rarely change our cluster configuration, so having the long connection string would be more reliable If these changes should be approached in some other manner, I'd be happy to do that. * Update mongodbUrl.js Co-authored-by: Diamond Lewis <[email protected]>
1 parent 68a1b30 commit 12abae8

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/vendor/mongodbUrl.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const portPattern = /:[0-9]*$/;
4040
// Special case for a simple path URL
4141
const simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/;
4242

43-
const hostnameMaxLen = 255;
4443
// protocols that can allow "unsafe" and "unwise" chars.
4544
const unsafeProtocol = {
4645
javascript: true,
@@ -293,12 +292,8 @@ Url.prototype.parse = function (url, parseQueryString, slashesDenoteHost) {
293292
if (result !== undefined) rest = result;
294293
}
295294

296-
if (this.hostname.length > hostnameMaxLen) {
297-
this.hostname = '';
298-
} else {
299-
// hostnames are always lower case.
300-
this.hostname = this.hostname.toLowerCase();
301-
}
295+
// hostnames are always lower case.
296+
this.hostname = this.hostname.toLowerCase();
302297

303298
if (!ipv6Hostname) {
304299
// IDNA Support: Returns a punycoded representation of "domain".

0 commit comments

Comments
 (0)