[FIXED] Unable to connect to the database. Retrying

Issue

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

I solved by updating manually mongoose version to 6.2.2

 WARN @nestjs/mongoose@9.0.2 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 mongoose@6.2.2 --save

Answered By – Carlos E Torres Fernández

Answer Checked By – David Marino (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published