Skip to content

Commit 60d22ee

Browse files
authored
Merge pull request #6411 from Countly/mongo-url-parse
[core] Fix mongo connection url parsing
2 parents edb9196 + c75afa5 commit 60d22ee

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Version 25.03.XX
2+
Fixes:
3+
- [core] Fix mongo connection url parsing
4+
15
## Version 25.03.10
26
Enterprise Fixes:
37
- [okta] Fix body parser middleware version mismatch causing OKTA authentication break

plugins/pluginManager.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ var pluginDependencies = require('./pluginDependencies.js'),
1111
apiCountlyConfig = require('../api/config', 'dont-enclose'),
1212
utils = require('../api/utils/utils.js'),
1313
fs = require('fs'),
14-
url = require('url'),
1514
querystring = require('querystring'),
1615
cp = require('child_process'),
1716
async = require("async"),
@@ -1877,9 +1876,21 @@ var pluginManager = function pluginManager() {
18771876
}
18781877

18791878
if (config && typeof config.mongodb === "string") {
1880-
var urlParts = url.parse(config.mongodb, true);
1881-
if (urlParts && urlParts.query && urlParts.query.maxPoolSize) {
1882-
maxPoolSize = urlParts.query.maxPoolSize;
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('?');
1888+
1889+
if (urlParts.length > 1) {
1890+
const queryParams = new URLSearchParams(urlParts[1]);
1891+
1892+
maxPoolSize = queryParams.get('maxPoolSize') !== null ? queryParams.get('maxPoolSize') : maxPoolSize;
1893+
}
18831894
}
18841895
}
18851896
else {

0 commit comments

Comments
 (0)