问题:在win7上运行python脚本无法连接到virtualbox上的mongodb数据库,但是在virtualbox中的linux系统上却可以
解决方法: 修改 /etc/mongodb.conf文件的bind_ip,允许同网段的ip地址接入
原因分析:
/etc/mongodb.conf文件的bind_ip默认值为127.0.0.1:
所以,即使脚本的ip地址是virtualbox中的linux server地址也无法连接成功(测试环境virtualbox的linux server ip即为192.168.56.101):
解决步骤:
现在修改 /etc/mongodb.conf:
运行结果:
脚本代码见:CSDN pymongo实现对mongodb进行增删改查操作
(代码中的host 修改为virtualbox中运行mongodb的linux server地址即可)
推荐阅读:
http://www.mkyong.com/mongodb/mongodb-allow-remote-access/