From c78a8e71b9e8dd18e16f2b16dce3214c4ae1a4c5 Mon Sep 17 00:00:00 2001 From: Nicholas Whitney <117346926+nicholaswhitney@users.noreply.github.com> Date: Thu, 3 Nov 2022 11:28:09 +0100 Subject: [PATCH] Fix template: MongoDB database name parsing From the feathers discord: The current parsing method fails the following MongoDB connection string: ``` mongodb://user:P%40ss@localhost:27017/databaseName?authSource=admin ``` Where it parses `databaseName?authSource=admin` as the database name instead of just `databaseName`. The following change should parse all database connection strings correctly. --- packages/cli/src/connection/templates/mongodb.tpl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/connection/templates/mongodb.tpl.ts b/packages/cli/src/connection/templates/mongodb.tpl.ts index 4c17545d91..6e3dae2349 100644 --- a/packages/cli/src/connection/templates/mongodb.tpl.ts +++ b/packages/cli/src/connection/templates/mongodb.tpl.ts @@ -14,7 +14,7 @@ declare module './declarations' { export const mongodb = (app: Application) => { const connection = app.get('mongodb') as string - const database = connection.substring(connection.lastIndexOf('/') + 1) + const database = new URL("mongodb://localhost").pathname.substring(1) const mongoClient = MongoClient.connect(connection) .then(client => client.db(database))