CodeMed CodeMed - 1 year ago 173
Node.js Question

Point mongoos.connect at localhost mongodb

I am studying the MEAN stack by using this tutorial. But the tutorial connects to a remote mongodb installation. I have MongoDB running in the CentOS7 localhost.

How do I alter the mongoose connect line in server.js from the tutorial link above to connect to a localhost database instead of a remote database?
Here is the current line from

that needs to be changed to point to the localhost mongodb:


A specific mongodb database has not been created yet. Do I need to create that also?

Answer Source

I'm fairly new at Mongo to, but I know how to connect to a local db. Basically I had to do the following:

mongod --dbpath [YOUR_DB_PATH]

  • Created a DB use mydb
  • With that you should have already a mongodb db instance looking for connections on default port. So you can change that line for this:


Again, this is really basic and it is creating a mongo DB connection with all default options. So this will keep you rolling, but you may need to dig a bit more for custom options.

Hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download