简体   繁体   English

使用 PyMongo 在不同系统上连接 MongoDB

[英]Connecting with MongoDB on different system using PyMongo

I have MongoDB working on my MacBook and I am using it in the flask app to save my form data.我有 MongoDB 在我的 MacBook 上工作,我在 flask 应用程序中使用它来保存我的表单数据。 Now I also have a windows 10 system in my lab at the institution and I can connect to it via VPN and now I want to run my flask app on my mac and save the form data on that windows 10 system.现在我在该机构的实验室里也有一个 windows 10 系统,我可以通过 VPN 连接到它,现在我想在我的 Mac 上运行我的 flask 应用程序并将表单数据保存在该 Z0F4137ED1502B55445D6 系统上。 I am using pymongo for connection.我正在使用 pymongo 进行连接。

client = pymongo.MongoClient('localhost', 27017)
db = client.user_login_system

I tried changing the 'localhost' to the windows 10 system IP but it didn't work.我尝试将“本地主机”更改为 windows 10 系统 IP 但它不起作用。 Is there any way to connect to the windows 10 MongoDB from my mac using pymongo?有什么方法可以使用 pymongo 从我的 mac 连接到 windows 10 MongoDB?

By default MongoDB only allows connections from the local machine ;默认情况下MongoDB 只允许来自本地机器的连接 you can widen access in the mongod.conf file.您可以在 mongod.conf 文件中扩大访问范围。

On your windows machine, edit your /bin/mongod.cfg file and set the net section to:在您的 windows 机器上,编辑您的 /bin/mongod.cfg 文件并将net部分设置为:

net:
   bindIpAll: true
   port: 27017

and then restart the MongoDB service, then try it again.然后重启MongoDB服务,然后再试一次。

References: https://docs.mongodb.com/manual/reference/configuration-options/.net-options https://docs.mongodb.com/manual/reference/configuration-options/.net.bindIp References: https://docs.mongodb.com/manual/reference/configuration-options/.net-options https://docs.mongodb.com/manual/reference/configuration-options/.net.bindIp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM