database - Strapi 连接到 atlas Mongo 数据库时出错
问题描述
我想将 mongo atlas 与strapi 一起使用。所以我正在读取值.env
这些是设置
connections: {
default: {
connector: 'mongoose',
settings: {
host: env('DB_MONGO_URL', '127.0.0.1'),
srv: env.bool('DATABASE_SRV', false),
port: env.int('DB_PORT', 27017),
database: env('DATABASE_NAME', 'mydb'),
username: env('DB_USER_NAME', null),
password: env('DB_PASSWORD', null)
},
options: {
authenticationDatabase: env('AUTHENTICATION_DATABASE', null),
ssl: env.bool('DB_SSL_ENABLE', false),
},
},
这是价值观
DB_MONGO_URL=myproject.random.mongodb.net/mydbt?ssl_cert_reqs=CERT_NONE
DB_USER_NAME=myuser
DB_PASSWORD=mypasswor
但这显示
[2021-10-12T13:18:25.485Z] debug ⛔️ Server wasn't able to start properly.
[2021-10-12T13:18:25.490Z] error Error connecting to the Mongo database. Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
error Command failed with exit code 1.
在我允许的网络中0.0.0.0
,包括任何 IP 地址。
如果我在MongoDB Compass中传递这个 url
mongodb+srv://myproject.random.mongodb.net/mydbt?ssl_cert_reqs=CERT_NONE
那么这有效
我也试过了
DB_MONGO_URL=mongodb+srv://myproject.random.mongodb.net/mydbt?ssl_cert_reqs=CERT_NONE
DB_USER_NAME=myuser
DB_PASSWORD=mypassword
但这表明
[2021-10-13T06:59:01.372Z] debug ⛔️ Server wasn't able to start properly.
[2021-10-13T06:59:01.374Z] error Error connecting to the Mongo database. getaddrinfo ENOTFOUND mongodb+srv
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
如果我尝试启用srv
true
[2021-10-13T07:01:20.065Z] debug ⛔️ Server wasn't able to start properly.
[2021-10-13T07:01:20.067Z] error Error connecting to the Mongo database. URI does not have hostname, domain name and tld
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
我该如何解决这个问题?
解决方案
推荐阅读
- php - 实现 AJAX 搜索表后,重写 jQuery 脚本以使用动态链接链接表行
- python - 如何使用 Putty 在 Python 中设置 Cron 作业(操作系统为 Linaro)
- typescript - 设置 TypeScript 编译器的基本/工作目录
- java - 在 HQL 中查找日期之间的实体
- angular - 在 AngularFirestoreCollection 中转换 CollectionReference
还是可观察的? - python - Python - 将 For Loop 编写为文件作为生成器而不是 str/dict
- vba - 将全名从批处理文件传递到 vbs 文件,然后用它运行一个 word 宏
- python-3.x - QtDesigner5.11.0、python3.5和pyside2之间的兼容性问题?
- python - 为什么即使在 Python 中的新请求中,变量也会保留在内存中?
- batch-file - .bat 文件中的 NEQ "NOPROMPT" 有什么作用?