Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build a REST API With Express Modeling Data for the API Connecting Mongoose to MongoDB

Dennis Klarenbeek
Dennis Klarenbeek
17,168 Points

Get no connection to mongod.

I don't get the connection to the Mongodb server because I get the following error:

[MongoError: connect ECONNREFUSED 127.0.0.1:27017] name: 'MongoError', message: 'connect ECONNREFUSED 127.0.0.1:27017' }

I tried to run mongo by starting mongod but I get the -bash: mongod: command not found. Afterwards I tried to mkdir -p /data/db but also this won't solve the problem.

Can somebody help me?

4 Answers

Seth Kroger
Seth Kroger
56,413 Points

It depends on how you installed mongo and on what system/OS, but it looks like mongod/mongo wasn't added to your PATH (the list of directories with executable commands that can be run from the command-line).

Charles Li
Charles Li
15,557 Points

Did you figure out how to solve the problem? I'm facing the same error message as well. Thanks!

Charles Li
Charles Li
15,557 Points

I installed with homebrew

Dennis Klarenbeek
Dennis Klarenbeek
17,168 Points

Hi Seth,

I have installed MongoDB on the folder and global. I'm using Mac OSx as operating system.

Seth Kroger
Seth Kroger
56,413 Points

Did you use Homebrew or the manual method? Both described here: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

If you remove the port from the connection string it should work. Based on documentation, the port should work; however, it does not for me either ... investigating why ...

// mongoose.connect('mongodb://localhost:27107/sandbox');
mongoose.connect('mongodb://localhost/sandbox');