I\'m using NodeJS wih MongoDB using mongodb package. When I run mongod command it works fine and gives "waiting for connection on port 27017". So, mongod seems to
For Ubuntu users run
sudo systemctl restart mongod
Try to start mongoDB server by giving the --dbpath with mongod.
sudo mongod --dbpath /var/lib/mongo/data/db &
'&' in the last will start the mongodb server as service on your server.
Hope it Works.
In my particular instance, I was connected to a VPN and that was blocking the localhost connection to MongoDB somehow. It worked when I disconnected my VPN. It's a special case, but good to know nonetheless. So anything impeding your network connectivity, Get that fixed.
I had the same error because i had not installed mongoDB. Make sure that you have mongodb installed and if not, you can download it from here https://www.mongodb.com/download-center/community
For Windows users.
This happens because the MondgDB server is stopped. to fix this you can,
1 search for Services ,for that search using the left bottom corner search option.
2 then there is a gear icon named with 'Services'.
3 after clicking that you will get a window with lot of services
4 scroll down and you will find 'MongoDB server (MongoDB)'.
5 so you will see that there is an option to start the service.
6 start it.
1 then open your command prompt.
2 type mongod
now you can connect to your server.
this steps also working fine if your sql server service down. (find sql server services)
This happened probably because the MongoDB service isn't started. Follow the below steps to start it:
The server will start. Now execute npm start
again and the code might work this time.