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

Connect to mLab mongoDB database using nodeJS Strapi

我刚开始使用 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

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

我是 Strapi 的创建者 Pierre。我尝试了以下配置并且效果很好:

{ "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 不要忘记指定 authenticationDatabase

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