如何在本地网络内连接另一台机器mongodb数据库? [英] how to connect another machine mongodb database inside local network ?

查看:786
本文介绍了如何在本地网络内连接另一台机器mongodb数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循此猫鼬文档在此处输入链接描述

mongoose.connect('mongodb://localhost/waterDB');

使用它,我可以连接本地计算机waterDB mongoDB数据库

Using This, I can connect local machine waterDBmongoDB DataBase

我的个人计算机本地IP:192.168.1.5

My Personal Machine Local IP : 192.168.1.5

我的服务器计算机本地IP:192.168.1.100

My Server Machine Local IP : 192.168.1.100

两台机器都有waterDB数据库.这两个数据库都没有用户名和密码

Both machine have waterDB DataBase . There is no username and password for both DB

我想在我的个人计算机内部连接服务器计算机waterDB.

I wanted to connect Server Machine waterDB Inside My Personal Machine.

据此:mongoose.connect('mongodb://username:password@host:port/database?options...');

我尝试:mongoose.connect('mongodb://192.168.1.100:27017/waterDB');

但是

MongoError: failed to connect to server [192.168.1.100:27017] on first connect
at null.<anonymous> (/home/water/node_modules/mongodb-core/lib/topologies/server.js:313:35)
at emitOne (events.js:77:13)
at emit (events.js:169:7)
..........

有什么解决方案的错误吗?

Any solution for err ?

谢谢(@ _ @)

推荐答案

您的MongoDB实例仅在本地主机上侦听可能是一个问题. 您可以在MongoDB的配置文件中更改绑定地址.配置文件可能位于/etc/mongodb.conf/etc/mongod.conf中.还有2种配置文件格式:

It might be a problem with your MongoDB instance listening on localhost only. You can change the bind address in MongoDB's configuration file. The config file may be located in /etc/mongodb.conf or /etc/mongod.conf. There are also 2 config file formats:

旧格式(仍受支持):

bind_ip = 0.0.0.0

YAML(版本2.6及更高版本):

YAML (version 2.6+):

net:
    bindIp: 0.0.0.0

更改配置文件后,您必须重新启动MongoDB服务器.

After changing the config file you have to restart the MongoDB server.

这篇关于如何在本地网络内连接另一台机器mongodb数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆