设置MONGO

编程入门 行业动态 更新时间:2024-10-09 09:17:39
设置MONGO_URL不从本地运行应用远程mongo连接到Atlas(Setting MONGO_URL not applying remote mongo connection to Atlas from local run)

我正在尝试从本地运行连接到MongoDB Atlas上的远程mongodb设置。 我有一个来自Compose的正常mongo url:

MONGO_URL=mongodb://[username]:[password]@aws-us-east-1-portal.21.dblayer.com:10170/[database]

这适用于本地运行和部署到Galaxy的远程连接。

我已经使用Atlas创建了一个更复杂的副本集设置,并希望从本地开发和生产中连接到该数据库集。 Atlas网址如下所示:

MONGO_URL=mongodb://[username]:[password]@cluster0-shard-00-00-xgnuk.mongodb.net:27017,cluster0-shard-00-01-xgnuk.mongodb.net:27017,cluster0-shard-00-02-xgnuk.mongodb.net:27017/[database]?ssl=true&replicaSet=Cluster0-shard-0&readPreference=primaryPreferred&w=majority&authSource=admin

当我部署到Galaxy时,我的应用程序成功连接到所需的Atlas数据库。 但是,当我尝试将url本地设置为远程数据库时,就像我使用compose url一样,我的本地app实例只连接到我的本地mongodb而没有警告或错误。

我尝试使用网址中的选项设置,但没有成功。 我有什么想法可以做到这一点?

(未启用分片)

I'm trying to connect to a remote mongodb setup on MongoDB Atlas from a local run. I have a normal mongo url from Compose:

MONGO_URL=mongodb://[username]:[password]@aws-us-east-1-portal.21.dblayer.com:10170/[database]

This works fine for remote connection on local runs and for deployment to Galaxy.

I have made a more complex replica set setup with Atlas and would like to connect to that database set from local development and in production. The Atlas url looks like this:

MONGO_URL=mongodb://[username]:[password]@cluster0-shard-00-00-xgnuk.mongodb.net:27017,cluster0-shard-00-01-xgnuk.mongodb.net:27017,cluster0-shard-00-02-xgnuk.mongodb.net:27017/[database]?ssl=true&replicaSet=Cluster0-shard-0&readPreference=primaryPreferred&w=majority&authSource=admin

When I deploy to Galaxy, my app connects successfully to the desired Atlas database. However, when I try to set the url locally to the remote database, like I use to with the compose url, my local app instance only connects to my local mongodb with no warnings or errors.

I tried playing around with the option settings in the url, but with no success. Any ideas how I can achieve this?

(No sharding is enabled)

最满意答案

在环境变量中使用“&”字符可能会有问题(Mac OS)。 请务必在引号中键入变量:

MONGO_URL='mongodb://[username]:[password]@cluster0-shard-00-00-xgnuk.mongodb.net:27017,cluster0-shard-00-01-xgnuk.mongodb.net:27017,cluster0-shard-00-02-xgnuk.mongodb.net:27017/[database]?ssl=true&replicaSet=Cluster0-shard-0&readPreference=primaryPreferred&w=majority&authSource=admin'

更多细节在这里:

https://forums.meteor.com/t/setting-mongo-url-not-applying-remote-mongo-connection-to-atlas-from-local-run/29718/5

https://docs.mongodb.com/manual/reference/connection-string/

Using '&' chars in a environment variable can be problematic (Mac OS). Be sure to type the variable in quotes:

MONGO_URL='mongodb://[username]:[password]@cluster0-shard-00-00-xgnuk.mongodb.net:27017,cluster0-shard-00-01-xgnuk.mongodb.net:27017,cluster0-shard-00-02-xgnuk.mongodb.net:27017/[database]?ssl=true&replicaSet=Cluster0-shard-0&readPreference=primaryPreferred&w=majority&authSource=admin'

More details here:

https://forums.meteor.com/t/setting-mongo-url-not-applying-remote-mongo-connection-to-atlas-from-local-run/29718/5

https://docs.mongodb.com/manual/reference/connection-string/

更多推荐

本文发布于:2023-08-03 23:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1402400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MONGO

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!