【问题标题】:not able to connect to Atlas database from strapi project无法从 Strapi 项目连接到 Atlas 数据库
【发布时间】:2020-05-20 13:05:49
【问题描述】:

我是strapi框架的新手。我才知道strapi和atlas现在在一起了。我可以从本地终端连接到 atlas 帐户,但无法从 strpi 项目连接,出现以下错误。我在 stackoverflow 中看到旧主题讨论相同的错误,但strapi 已升级,数据库配置似乎已更改,这些解决方案都不起作用。

[2020-05-20T12:57:23.957Z] 调试⛔️ 服务器无法正常启动。 [2020-05-20T12:57:23.959Z] 错误确保您的 MongoDB 数据库正在运行..

下面是config/environemnts/development/database.json的内容

  "defaultConnection": "default",
  "connections": {
    "default": {
      "connector": "strapi-hook-mongoose",
      "settings": {
        "client": "mongo",
        "host": "cluster0-58gdw.mongodb.net",
        "srv": "true",
        "port": 27017,
        "database": "brewhaha",
        "username": "temp123",
        "password": "temp123"
      },
      "options": {
        "authenticationDatabase": "",
        "ssl": true
      }
    }
  }
}

【问题讨论】:

    标签: node.js strapi mongodb-atlas


    【解决方案1】:

    如果你使用 mongodb 地图集,我建议使用 settings.uri

    {
      "defaultConnection": "default",
      "connections": {
        "default": {
          "connector": "mongoose",
          "settings": {
            "uri": "mongodb://paulbocuse:<password>@strapidatabase-shard-00-00-fxxx6c.mongodb.net:27017,strapidatabase-shard-00-01-fxxxc.mongodb.net:27017,strapidatabase-shard-00-02-fxxxc.mongodb.net:27017/test?ssl=true&replicaSet=strapidatabase-shard-0&authSource=admin&retryWrites=true&w=majority"
          },
          "options": {
            "ssl": true
          }
        }
      }
    }
    

    按照中列出的所有步骤,获取您的“uri”: https://strapi.io/documentation/3.0.0-beta.x/guides/databases.html#install-on-atlas-mongodb-atlas

    【讨论】:

      【解决方案2】:

      对于 Strapi 3.4.6。去config/database.js试试下面的配置。

      module.exports = ({ env }) => ({
        defaultConnection: 'default',
        connections: {
          default: {
            connector: 'mongoose',
            settings: {
              host: env('DATABASE_HOST', 'clusterX.XXXXX.mongodb.net'),
              srv: env.bool('DATABASE_SRV', true),
              port: env.int('DATABASE_PORT', 27017),
              database: env('DATABASE_NAME', 'mydb'),
              username: env('DATABASE_USERNAME', 'username'),
              password: env('DATABASE_PASSWORD', 'password'),
            },
            options: {
              authenticationDatabase: env('AUTHENTICATION_DATABASE', null),
              ssl: env.bool('DATABASE_SSL', true),
            },
          },
        },
      });

      【讨论】:

        猜你喜欢
        • 2019-04-04
        • 2020-10-12
        • 1970-01-01
        • 1970-01-01
        • 2019-08-17
        • 1970-01-01
        • 2021-06-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多