1.发现问题
当我在js试图使用mongoose连接mongodb数据库的时候发现系统报错
connect ECONNREFUSED ::1:27017
2.原因
原来是在连接的时候使用了localhost进行数据库的连接导致的报错
mongoose.connect("mongodb://localhost:27017/chat",{ //连接MongoDB数据库
}).then(() => {
console.log("Connected to MongoDB");
}).catch(err => {
console.log(err.message);
});
3.解决问题
将localhost改成本地IP就可以了
mongoose.connect("mongodb://localhost:27017/chat",{ //连接MongoDB数据库
}).then(() => {
console.log("Connected to MongoDB");
}).catch(err => {
console.log(err.message);
});