我正在尝试从本地运行连接到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=adminWhen 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/
更多推荐
发布评论