Skip to content

Commit e0e4f24

Browse files
committed
feat(mongo): enhance custom MongoDB connection string handling
- Introduced a new utility function to build the MongoDB connection string dynamically, ensuring the database name is correctly set in the URL. - Updated the custom connection string logic to utilize the new function, improving clarity and maintainability. These changes enhance the flexibility of MongoDB configurations, ensuring accurate connection strings are generated based on provided parameters. Signed-off-by: Innei <tukon479@gmail.com>
1 parent 23abde6 commit e0e4f24

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

apps/core/src/app.config.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,17 @@ export const CROSS_DOMAIN = {
234234
}
235235

236236
const customConnectionString = argv.db_connection_string || MONGO_CONNECTION
237+
238+
function buildMongoConnectionString(
239+
connectionString: string,
240+
dbName: string,
241+
): string {
242+
const url = new URL(connectionString)
243+
// Replace or set the pathname to the database name
244+
url.pathname = `/${dbName}`
245+
return url.toString()
246+
}
247+
237248
export const MONGO_DB = {
238249
dbName: argv.collection_name || 'mx-space',
239250
host: argv.db_host || '127.0.0.1',
@@ -250,7 +261,7 @@ export const MONGO_DB = {
250261
},
251262
get customConnectionString() {
252263
return customConnectionString
253-
? `${customConnectionString}/${this.dbName}`
264+
? buildMongoConnectionString(customConnectionString, this.dbName)
254265
: undefined
255266
},
256267
}

0 commit comments

Comments
 (0)