Не получается в NestJS подключиться к MongoDB, Windows
У меня не получается подключиться к mongoDB в NestJS, mongoDB запущен в Windows, не в Linux.
Вот такое подключение к базе данных:
const mongoDBUrl = 'mongodb://root:root@localhost:27017/nest-auth?authSource=admin&authMechanism=SCRAM-SHA-1';
@Module({
imports: [
MongooseModule.forRoot(mongoDBUrl),
UsersModule,
AuthModule
],
controllers: [AppController, AuthController],
providers: [AppService, AuthService],
})
export class AppModule {}
Также изменён файл mongod.cfg
, в нём раскомментирована строчка и так написано:
security:
authorization: enabled
Перед этим всем я заходил в MongoDB Compass, создавал пользователя со всеми правами для аутентификации в БД. Я могу успешно заходить в MongoDB Compass по такой же URI, но NestJS не хочет.
Полная ошибка в консоли такая:
[Nest] 20072 - 13.01.2023, 17:08:26 ERROR [MongooseModule] Unable to connect to the database. Retrying (1)...
[Nest] 20072 - 13.01.2023, 17:08:59 ERROR [MongooseModule] Unable to connect to the database. Retrying (2)...
[Nest] 20072 - 13.01.2023, 17:09:32 ERROR [MongooseModule] Unable to connect to the database. Retrying (3)...
[Nest] 20072 - 13.01.2023, 17:10:05 ERROR [MongooseModule] Unable to connect to the database. Retrying (4)...
[Nest] 20072 - 13.01.2023, 17:10:38 ERROR [MongooseModule] Unable to connect to the database. Retrying (5)...
[Nest] 20072 - 13.01.2023, 17:11:11 ERROR [MongooseModule] Unable to connect to the database. Retrying (6)...
[Nest] 20072 - 13.01.2023, 17:11:44 ERROR [MongooseModule] Unable to connect to the database. Retrying (7)...
[Nest] 20072 - 13.01.2023, 17:12:17 ERROR [MongooseModule] Unable to connect to the database. Retrying (8)...
[Nest] 20072 - 13.01.2023, 17:12:50 ERROR [MongooseModule] Unable to connect to the database. Retrying (9)...
[Nest] 20072 - 13.01.2023, 17:12:50 ERROR [ExceptionHandler] connect ECONNREFUSED ::1:27017
MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at NativeConnection.Connection.openUri (C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\mongoose\lib\connection.js:825:32)
at Mongoose.createConnection (C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\mongoose\lib\index.js:351:10)
at Function.<anonymous> (C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\@nestjs\mongoose\dist\mongoose-core.module.js:62:69)
at Generator.next (<anonymous>)
at C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\@nestjs\mongoose\dist\mongoose-core.module.js:20:71
at new Promise (<anonymous>)
at __awaiter (C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\@nestjs\mongoose\dist\mongoose-core.module.js:16:12)
at C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\@nestjs\mongoose\dist\mongoose-core.module.js:61:80
at Observable._subscribe (C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\rxjs\src\internal\observable\defer.ts:55:15)
at Observable._trySubscribe (C:\Users\mihinov\Desktop\my-works\nest-auth\node_modules\rxjs\src\internal\Observable.ts:244:19)
В чём может быть потенциальная ошибка?