'Unable to connect to the database. Retrying
I'm trying to connect to the database, seems like the set-up is correct, but for some reason, it says that it is not available.
app.module.ts
import { Module } from "@nestjs/common"
import { MongooseModule } from "@nestjs/mongoose";
import { ConfigModule } from "../config";
import { CreatorModule } from "./creator.module";
@Module({
imports: [
MongooseModule.forRoot('mongodb://localhost:27017/snaptoon', {
useCreateIndex: true,
useUnifiedTopology: true,
useNewUrlParser: true,
}),
CreatorModule,
],
controllers: [],
providers: []
})
export class AppModule {}
The error is: ERROR [MongooseModule] Unable to connect to the database. Retrying (9)...
I'm using '@nestjs/mongoose': '9.0.2'
Solution 1:[1]
I solved by updating manually mongoose version to 6.2.2
WARN @nestjs/[email protected] requires a peer of mongoose@^6.0.2 but none is installed. You must install peer dependencies yourself.
I realize due to this error on npm install
just use:
npm install [email protected] --save
Solution 2:[2]
For those people who cannot solve this problem by the answer above, according to the new specs of nestjs/mongoose.
It might be solved by deleting the line: useNewUrlParser: true.
For me, it works in both ways.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Carlos E Torres Fernández |
| Solution 2 | Daniil Sinelnik |
