【问题标题】:Unable to connect to the database - Mongoose nestJS无法连接到数据库 - Mongoose nestJS
【发布时间】:2021-06-27 23:28:01
【问题描述】:

目前我尝试连接到数据库 mongodb。但我得到它的错误:

[MongooseModule] Unable to connect to the database. Retrying (1)... +30015ms

我通过 openshift 使用连接,类似这样:

oc port-forward mongors-0 27019:27017

在nestJs的代码配置中,我遵循:

    @Module({
  imports: [MongooseModule.forRoot( serviceConfig.mongoUrl, { useNewUrlParser: true, useUnifiedTopology: false }),
    CommonModule, AccountingModule],
  controllers: [AppController],
})
export class AppModule { }

问题是当我使用这个配置选项时:useUnifiedTopology: true,当我使用值 false 时连接是正确的。

serviceConfig.mongoUrl 的值为:

mongodb://localhost:27019/PAGOS

如果有人可以帮助我,我很感激。

谢谢 问候

【问题讨论】:

  • 所有重试完成后,错误是什么?这里没有什么可做的。
  • 您好@JayMcDoniel,在完成所有重试后,应用程序无法运行并抛出此错误:MongooseServerSelectionError: getaddrinfo ENOTFOUND

标签: mongodb mongoose nestjs


【解决方案1】:

尝试更改localhost => 127.0.0.1

我有同样的问题,这很好用

【讨论】:

    猜你喜欢
    • 2021-05-11
    • 2021-04-11
    • 2022-08-03
    • 2021-02-17
    • 2020-07-21
    • 2021-10-19
    • 2020-10-20
    • 2020-12-28
    • 2020-04-03
    相关资源
    最近更新 更多