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!

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

Databases Mongo Basics Understanding MongoDB Store Your Blog In Mongo

Henry Lay
Henry Lay
14,739 Points

Terminal not loading when i typed in mongo

Hi guys,

had a error when i entered mongo command, and for whatever reason I can't seem to get it connected.

here was the error code on my terminal

Henrys-MacBook-Pro:treehouse-mongo-basics henrylay$ mongo MongoDB shell version v4.0.3 connecting to: mongodb:// 2018-11-06T21:35:33.580+1100 E QUERY [js] Error: couldn't connect to server, connection attempt failed: SocketException: Error connecting to :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:257:13 @(connect):1:6 exception: connect failed

1 Answer

Ken Alger
Ken Alger
Treehouse Teacher


Do you have the mongod service running on your local machine on port 27017?

To run the mongo command successfully and launch an instance of the mongo shell, you'll need to have the actual database running. Without a database to connect to, you'll typically get the error you mentioned.

Post back if you're still stuck.