I am writing this line of code to connect to mongodb via mongoose.
var db=mongoose.connect('mongodb://localhost/bookapi');
But this is showing this error in command prompt.
Error: connect ECONNREFUSED 127.0.0.1:27017
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
Help Please.
I just have to Run mongod from cmd. That was creating the error.
This error primarily means that the node server cannot connect to the mongodb instance.
Reasons:
Is the mongod service running?
If the mongo db is not on localhost, check internet connectivity, firewall permissions.
Try connecting to mongodb://localhost:27017/bookapi
Check if mongoose is installed and running. if you are using windows please refer this https://docs.mongodb.org/v3.0/tutorial/install-mongodb-on-windows/ for adding mongodb as a service.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.