Skip to content

Commit 11b02a3

Browse files
committed
[core] Fix mongo connection url parsing
1 parent 64fd305 commit 11b02a3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

plugins/pluginManager.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,12 +1876,21 @@ var pluginManager = function pluginManager() {
18761876
}
18771877

18781878
if (config && typeof config.mongodb === "string") {
1879-
const urlParts = config.mongodb.split('?');
1879+
try {
1880+
const urlObj = new URL(config.mongodb);
1881+
// mongo connection string with multiple host like 'mongodb://localhost:30000,localhost:30001' will cause an error
1882+
1883+
maxPoolSize = urlObj.searchParams.get('maxPoolSize') !== null ? urlObj.searchParams.get('maxPoolSize') : maxPoolSize;
1884+
}
1885+
catch (_err) {
1886+
// we catch the error here and try to process only the query params part
1887+
const urlParts = config.mongodb.split('?');
18801888

1881-
if (urlParts.length > 1) {
1882-
const queryParams = new URLSearchParams(urlParts[1]);
1889+
if (urlParts.length > 1) {
1890+
const queryParams = new URLSearchParams(urlParts[1]);
18831891

1884-
maxPoolSize = queryParams.get('maxPoolSize') || maxPoolSize;
1892+
maxPoolSize = queryParams.get('maxPoolSize') !== null ? queryParams.get('maxPoolSize') : maxPoolSize;
1893+
}
18851894
}
18861895
}
18871896
else {

0 commit comments

Comments
 (0)