[英]MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017 in windows 7
I am working with MongoDB with the Nodejs.我正在使用 Nodejs 与 MongoDB 合作。 I have following index.js file,我有以下 index.js 文件,
const express= require('express');
const mongoose= require('mongoose');
const app= express();
const port=3000;
mongoose.connect('mongodb://127.0.0.1:27017/ThogaKade',{
useNewUrlParser:true,
useUnifiedTopology:true,
useFindAndModify:false,
useCreateIndex:true
}).then(()=>{
app.listen(port,()=>{
console.log(`Server Start on Port ${port}`)
})
}).catch(error=>{
console.log(error);
})
but when I execute nodemon
command it is en counting following error message here但是当我执行nodemon
命令时,它会在此处计算以下错误消息
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
how could I fix this problem?我该如何解决这个问题?
Make sure mongo service is properly installed and started https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/确保 mongo 服务已正确安装并启动https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
User and password are missing in your string.您的字符串中缺少用户名和密码。 See https://docs.mongodb.com/manual/reference/connection-string/请参阅https://docs.mongodb.com/manual/reference/connection-string/
Use the option authSource :使用选项authSource :
mongodb://<user>:<password>@127.0.0.1:27017/ThogaKade?authSource=admin
In this way, you are authenticating on database admin
and using database ThogaKade
for connection.通过这种方式,您在数据库admin
上进行身份验证并使用数据库ThogaKade
进行连接。
See https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/ too参见https://docs.mongodb.com/manual/tutorial/manage-users-and-roles/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.