使用 nodeJS Strapi 连接到 mLab mongoDB 数据库



我刚刚开始使用strapi框架,我想使用mLab作为我的mongoDB数据库,所以我去配置strapi并填写以下详细信息:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-mongoose",
      "settings": {
        "client": "mongo",
        "host": "localhost",
        "port": 27017,
        "database": "development",
        "username": "",
        "password": ""
      },
      "options": {}
    }
  }
}

我从mLab获得的详细信息是:

mongodb://myUsername:myPassword@ds047891.mlab.com:41365/myDatabase

这是我的最终配置:

{
  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-mongoose",
      "settings": {
        "client": "mongo",
        "host": "ds047891.mlab.com",
        "port": 41365,
        "database": "myDatabase",
        "username": "myUsername",
        "password": "myPassword"
      },
      "options": {}
    }
  }
}

当我尝试启动strapi时,出现以下错误:

DEBUG (2748 on DESKTOP-HAL1ATE): Server wasn't able to start properly.
ERROR (2748 on DESKTOP-HAL1ATE): (hook:mongoose) takes too long to load

我认为我没有正确设置配置,但我无法确定问题出在哪里。我希望有人可以,谢谢。

我是Pierre,Strapi的创造者。我尝试使用以下配置,效果很好:

{ "defaultConnection": "default", "connections": { "default": { "connector": "strapi-mongoose", "settings": { "client": "mongo", "host": "ds135777.mlab.com", "port": "35777", "database": "myDatabase", "username": "myUsername", "password": "myPassword" }, "options": {} } } }

我们的配置文件看起来很安静。

您更新了什么文件(/config/environment/development/database.json/config/environment/production/database.json(?

您确定输入了正确的用户名和密码吗?您是否尝试通过命令行mongo ds135777.mlab.com:35777/myDatabase -u <dbuser> -p <dbpassword>登录到MongoDB实例?

更新

在 mlab 的版本中>= 3 不要忘记指定身份验证数据库

"options": {
    "authenticationDatabase": "your_mlad_database_name",
    "ssl": false
  }

相关内容

  • 没有找到相关文章

最新更新