如何使用Mongo+ SRV连接到本地Docker MongoDB实例?

发布于 2025-02-02 18:12:49 字数 456 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文