I\'m new in nodeJS, started learning by following a trailer on youtube, everything goes well until I added the connect function if mongodb,
mongo.connect(\"m
this might help someone if you installed your mongo on .msi setup kindly open the software and select repair instead of install and try again, that works for me .
You have to install MongoDB
database server first in your system and start it.
Use the below link to install MongoDB
https://docs.mongodb.com/manual/installation/
1) If you haven't installed mongodb, install it.
2) open a new terminal, type "mongo". This is going to connect you to a MongoDB instance running on your localhost with default port 27017:
Your firewall blocked port 27017 which used to connect to MongoDB.
Try to find which firewall is being used in your system, e.g. in my case is csf, config file placed at
/etc/csf/csf.conf
find TCP_IN & TCP_OUT as follow and add port 27017 to allowed incoming and outgoing ports
# Allow incoming TCP ports
TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,2222,27017"
# Allow outgoing TCP ports
TCP_OUT = "20,21,22,25,53,80,110,113,443,587,993,995,2222,27017"
Save config file and restart csf to apply it:
csf -r
I faced same issue but after a lot of RND. I found that whts the problem so run this command on your terminal.
sudo service mongod start
then run mongo on terminal
Following the logic behind @CoryM's answer above :
After trying EVERY solution google came up with on stack overflow, I found what my particular problem was. I had edited my hosts file a long time ago to allow me to access my localhost from my virtualbox.
Removing this entry solved it for me...
I had edited my hosts file too for Python Machine Learning setup 2 months ago. So instead of removing it because I still need it, I use 127.0.0.1
in place of localhost
and it worked :
mongoose.connect('mongodb://127.0.0.1/testdb')