From 7fa2012897d8429b522fbca72211fc9be1c25f7e Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Fri, 18 Nov 2022 14:48:25 -0700 Subject: [PATCH] fix(cli): mongodb connection string for node 17+ (#2875) --- docs/api/databases/mongodb.md | 2 +- packages/cli/src/connection/index.ts | 2 +- packages/cli/test/generators.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api/databases/mongodb.md b/docs/api/databases/mongodb.md index cfc6eb6e10..2b43e75777 100644 --- a/docs/api/databases/mongodb.md +++ b/docs/api/databases/mongodb.md @@ -32,7 +32,7 @@ There are two typical setup steps for using `@feathersjs/mongodb` in an applicat ### Connect to the Database -Before using `@feathersjs/mongodb`, you'll need to create a connection to the database. This example connects to a MongoDB database similar to how the CLI-generated app connects. It uses `app.get('mongodb')` to read the connection string from `@feathersjs/configuration`. The connection string would be something similar to `mongodb://localhost:27017/my-app-dev` for local development or one provided by your database host. +Before using `@feathersjs/mongodb`, you'll need to create a connection to the database. This example connects to a MongoDB database similar to how the CLI-generated app connects. It uses `app.get('mongodb')` to read the connection string from `@feathersjs/configuration`. The connection string would be something similar to `mongodb://127.0.0.1:27017/my-app-dev` for local development or one provided by your database host. Once the connection attempt has been started, the code uses `app.set('monodbClient', mongoClient)` to store the connection promise back into the config, which allows it to be looked up when initializing individual services. diff --git a/packages/cli/src/connection/index.ts b/packages/cli/src/connection/index.ts index 27b20290fa..2c75039658 100644 --- a/packages/cli/src/connection/index.ts +++ b/packages/cli/src/connection/index.ts @@ -21,7 +21,7 @@ export type ConnectionGeneratorArguments = FeathersBaseContext & export const defaultConnectionString = (type: DatabaseType, name: string) => { const connectionStrings = { - mongodb: `mongodb://localhost:27017/${name}`, + mongodb: `mongodb://127.0.0.1:27017/${name}`, mysql: `mysql://root:@localhost:3306/${name}`, postgresql: `postgres://postgres:@localhost:5432/${name}`, sqlite: `${name}.sqlite`, diff --git a/packages/cli/test/generators.test.ts b/packages/cli/test/generators.test.ts index 5280e774b1..b6cdf3203c 100644 --- a/packages/cli/test/generators.test.ts +++ b/packages/cli/test/generators.test.ts @@ -73,7 +73,7 @@ describe('@feathersjs/cli', () => { { dependencyVersions, database: 'mongodb' as const, - connectionString: `mongodb://localhost:27017/${name}` + connectionString: `mongodb://127.0.0.1:27017/${name}` }, { cwd } )