@@ -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