I am on my typescript backend api project with nest, I am trying to configure my database with typeorm, with the following configuration: the problem being that it creates the database for me but it has the name "test" and name not "prosperity" which I specify in my .env file
It's as if he doesn't know the name I give him.
export function ormConfig(): any {
return {
type: 'mongodb',
host: process.env.DATABASE_HOST,
port: parseInt(process.env.DATABASE_PORT),
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
dbName: process.env.DATABASE_NAME,
synchronize: true,
logging: false,
autoLoadEntities: true,
useUnifiedTopology: true,
useNewUrlParser: true,
connectTimeout: parseInt(process.env.DATABASE_CONNECTION_TIME_OUT),
acquireTimeout: parseInt(process.env.DATABASE_ACQUIRE_TIME_OUT),
extra: {
connectionLimit: parseInt(process.env.DATABASE_CONNECTION_LIMIT),
},
entities: ['dist/**/entity/*.entity.js'],
migrations: ['dist/database/migrations/*.js'],
subscribers: ['dist/observers/subscribers/*.subscriber.js'],
cli: {
entitiesDir: 'src/components/**/entity',
migrationsDir: 'src/database/migrations',
subscribersDir: 'src/observers/subscribers',
},
};
}
NODE_ENV=development
SERVER_TIMEOUT=1080000
SERVER_PORT=3101
DATABASE_HOST=localhost
DATABASE_PORT=27017
DATABASE_USERNAME=admin
DATABASE_PASSWORD=password
DATABASE_NAME=prosperity
DATABASE_TYPE=mongodb
DATABASE_CONNECTION_TIME_OUT=150000
DATABASE_ACQUIRE_TIME_OUT=150000
DATABASE_CONNECTION_LIMIT=20
On the other hand, if I put "admin" as the base name and it already exists, it finds it and creates the associated collections there.
I know that the field we should put is not "dbName" but rather "database", Except that if I put "database", I get these errors:
"[Nest] 13236 - 26/10/2023 21:41:37 ERROR [TypeOrmModule] Unable to connect to the database. Retrying (1)..."
here is my appModule
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
TypeOrmModule.forRoot(ormConfig()),
AuthModule,
UserModule,
],
controllers: [],
providers: [],
})
export class AppModule {}
can you help me ? THANKS
I tried to put the minimum possible property in configuration typeorm, but it still doesn't work, database name is "Test". I just want it to generate my database with the right name