如何使用Mongo+ SRV连接到本地Docker MongoDB实例?
我正在使用2个Docker容器:1包含我的应用程序的后端,其中1个包含我正在使用的MongoDB实例,均在Linux机器上运行。我能够使用uri mongodb:// localhost:27017/
连接到MongoDB实例,但我的任务是使用mongo+srv
协议。我尝试了mongodb+srv://用户名:password@localhost/
,但是由于不允许LocalHost,IP地址也不起作用。我尝试了 this ,还试图将两个容器放在同一网络中并使用的主机名中的主机名mongo+srv
uri中的mongoDB容器,但我仍然不知道如何解决问题。 有什么想法吗?
I am working with 2 docker containers: 1 contains the back-end of my application and 1 contains the mongodb instance that I am using, both running on a linux machine. I was able to connect to the mongodb instance using the URI mongodb://localhost:27017/
, but I was tasked to use the mongo+srv
protocol instead. I tried mongodb+srv://username:password@localhost/
, but that doesn't work since localhost is not allowed, nor are IP addresses. I tried this and also tried to get the 2 containers to be in the same network and use the hostname of the mongodb container in the mongo+srv
URI, but I still don't know how to solve the problem.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论