I follow this mongoose document enter link description here
我按照这个mongoose文件在这里输入链接描述。
mongoose.connect('mongodb://localhost/waterDB');
Using This, I can connect local machine waterDB
mongoDB DataBase
使用这个,我可以连接本地机器waterDBmongoDB数据库
My Personal Machine Local IP : 192.168.1.5
我的个人机器本地IP: 192.168.1.5
My Server Machine Local IP : 192.168.1.100
我的服务器机器本地IP: 192.168.1.100
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.
我想在我的个人机器内部连接服务器机器waterDB。
According To This : mongoose.connect('mongodb://username:password@host:port/database?options...');
根据此:mongoose.connect('mongodb://username:password@host:port/database?options…');
I try : mongoose.connect('mongodb://192.168.1.100:27017/waterDB');
我试着:mongoose.connect(mongodb:/ / 192.168.1.100:27017 / waterDB);
But,
但是,
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 ?
有什么办法可以解决这个问题吗?
Thank (@_@)
谢谢(@_@)
2 个解决方案
#1
3
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:
这可能是您的MongoDB实例只监听本地主机的问题。可以在MongoDB的配置文件中更改绑定地址。配置文件可以位于/etc/mongodb中。conf或/etc/mongod.conf。还有两种配置文件格式:
Old format (still supported):
旧格式(仍然支持):
bind_ip = 0.0.0.0
YAML (version 2.6+):
YAML(版本2.6 +):
net:
bindIp: 0.0.0.0
After changing the config file you have to restart the MongoDB server.
更改配置文件之后,必须重新启动MongoDB服务器。
#2
1
Try without the Port no.
试着不要开港口号。
mongoose.connect('mongodb://192.168.1.100/waterDB');
this should work for you.
这应该对你有用。
But make sure both are connected on the same network, if you are connected on other network than your server is, then it wont work
但是要确保两者都连接在同一个网络上,如果您连接的网络不是您的服务器,那么它就不能工作
#1
3
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:
这可能是您的MongoDB实例只监听本地主机的问题。可以在MongoDB的配置文件中更改绑定地址。配置文件可以位于/etc/mongodb中。conf或/etc/mongod.conf。还有两种配置文件格式:
Old format (still supported):
旧格式(仍然支持):
bind_ip = 0.0.0.0
YAML (version 2.6+):
YAML(版本2.6 +):
net:
bindIp: 0.0.0.0
After changing the config file you have to restart the MongoDB server.
更改配置文件之后,必须重新启动MongoDB服务器。
#2
1
Try without the Port no.
试着不要开港口号。
mongoose.connect('mongodb://192.168.1.100/waterDB');
this should work for you.
这应该对你有用。
But make sure both are connected on the same network, if you are connected on other network than your server is, then it wont work
但是要确保两者都连接在同一个网络上,如果您连接的网络不是您的服务器,那么它就不能工作