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

Databases Mongo Basics Getting Started With MongoDB Setting Up MongoDB

Martin Coutts
Martin Coutts
18,154 Points

Connect failed

So I have ran mongod in first terminal window and get this

2018-06-06T07:58:30.849+0100 I CONTROL [initandlisten] MongoDB starting : pid=2404 port=27017 dbpath=/data/db 64-bit host=Martins-MBP 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] db version v3.6.5 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o 27 Mar 2018 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] allocator: system 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] modules: none 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] build environment: 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] distarch: x86_64 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] target_arch: x86_64 2018-06-06T07:58:30.850+0100 I CONTROL [initandlisten] options: {} 2018-06-06T07:58:30.850+0100 I STORAGE [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /data/db, terminating 2018-06-06T07:58:30.851+0100 I CONTROL [initandlisten] now exiting 2018-06-06T07:58:30.851+0100 I CONTROL [initandlisten] shutting down with code:100

then when I open a new window and type mongo I am getting

MongoDB shell version v3.6.5 connecting to: mongodb://127.0.0.1:27017 2018-06-06T07:58:45.386+0100 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused 2018-06-06T07:58:45.387+0100 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6 exception: connect failed

This doesn't look like the video

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Martin;

By looking at the information provided from the first terminal where you ran mongod, the Mongo Server never started due to the /data/db directory being read-only. If you change the permissions on that directory, you should be fine.

Post back if you're still stuck.

Ken

how do you change the permissions? I'm having the same problem.

Ken Alger
Ken Alger
Treehouse Teacher

Marshall Bradley, what operating system are you using? You generally can "right-click" on that folder name and get access to a permissions setting. Sometimes you'll need to do it through the command line but that will depend on the system you're using, typically.

Martin Coutts
Martin Coutts
18,154 Points

So I got round it by running sudo mongod on my Mac which gets round the permissions and then opening mongo in a new terminal window

thanks man. i literally found that out about 5 minutes after i posted in here

Diego ROJAS
Diego ROJAS
1,781 Points

How much of a genius are you?

Martin Coutts
Martin Coutts
18,154 Points

Haha that’s exactly what happens to me 95% of the time