I'm running my mongodb in virtualbox using vagrant. I'm trying to connect to the database on my host machine using node.js, but I get thrown a strange err when trying to do so. This is the code i'm running.
// This is not executed at all in Mozilla Firefox user.js.
user_pref( 'browser.display.background_color', ( 1 === 2 ? '#000000' : '#FFFFFF' ) );
This is the error that is shown in command line.
user_pref()
And this is a relevant part of the Vagrantfile.
window.location.href
答案 0 :(得分:0)
如果您正在使用vagrant进行本地运行的某些开发/测试,只需使用静态IP 它将简化您的生活。
您可以从Vagrantfile中删除所有转发的端口行,并替换为:
config.vm.network :private_network, ip: "192.168.33.10"
在VM中,您需要确保mongo绑定到此IP或0.0.0.0,以便它可以监听所有网络接口,在/etc/mongod.conf
文件中,确保
bind_ip=0.0.0.0
或
bind_ip=192.168.33.10
在您的节点代码中,您需要将mongo的url替换为mongodb://192.168.33.10:27017/test
(假设mongo在端口27017上运行;如果您在conf文件中进行了更改,请在此处对齐)