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

Zack Guo
Zack Guo
12,135 Points

Run mongod got a error

I used mac, install mongo by brew, when I run mongod, I got this error:

➜  ~ mongod
2017-09-13T14:16:50.808+0800 I CONTROL  [initandlisten] MongoDB starting : pid=11061 port=27017 dbpath=/data/db 64-bit host=GZ.lan
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] db version v3.4.9
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2l  25 May 2017
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] allocator: system
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] modules: none
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] build environment:
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten]     distarch: x86_64
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten]     target_arch: x86_64
2017-09-13T14:16:50.809+0800 I CONTROL  [initandlisten] options: {}
2017-09-13T14:16:50.810+0800 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-09-13T14:16:50.810+0800 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-09-13T14:16:50.814+0800 E STORAGE  [initandlisten] WiredTiger error (13) [1505283410:814035][11061:0x7fffabd083c0], file:WiredTiger.wt, connection: /data/db/WiredTiger.turtle: handle-open: open: Permission denied
2017-09-13T14:16:50.824+0800 I -        [initandlisten] Assertion: 28595:13: Permission denied src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 269
2017-09-13T14:16:50.826+0800 I STORAGE  [initandlisten] exception in initAndListen: 28595 13: Permission denied, terminating
2017-09-13T14:16:50.826+0800 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-09-13T14:16:50.826+0800 I NETWORK  [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-09-13T14:16:50.826+0800 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-09-13T14:16:50.826+0800 I CONTROL  [initandlisten] now exiting
2017-09-13T14:16:50.826+0800 I CONTROL  [initandlisten] shutting down with code:100

Can anyone helps please

try running as admin ~sudo mongod

3 Answers

Cosimo Scarpa
Cosimo Scarpa
14,047 Points
  • Open the Terminal app and type brew update.
  • After updating Homebrew brew install mongodb
  • After downloading Mongo, create the “db” directory. This is where the Mongo data files will live. You can create the directory in the default location by running mkdir -p /data/db Make sure that the /data/db directory has the right permissions by running

sudo chown -R id -un /data/db

Enter your password

Run the Mongo daemon, in one of your terminal windows run mongod. This should start the Mongo server. To stop the Mongo daemon hit ctrl-c

More info here

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Zack -

While sudo would work as Kanishkah Anwari mentioned, a better practice is to make sure that the user who is starting the monogod instance has write permission to the /data/db folder. Running things in sudo mode can open up other issues in general.

Post back if that doesn't work and we can help trouble shoot further from there.

Ken

Zack Guo
Zack Guo
12,135 Points

"~sudo mongod" works. Thank u guys!

Cristian Romero
Cristian Romero
11,911 Points

Hey Ken,

so currently I have to run in one window sudo mongod and then open another window and run mongo in order to the shell to start.. How would I go about automating that process? I use to be able to run mongo and the shell would start automatically from my user.. but for some reason maybe an update I can not do that.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Christian Romero -

I'm sure you could write a bash script or something that would allow you to type something akin to start-mongo and the script would start the mongod instance then launch a new terminal window with mongoshell running.

Depending on your use case, MongoDB's recommended best practice at this point is to use MongoDB Atlas as it is much easier to work with than having to manage your own servers. Atlas, as a product, was released after the Treehouse content was produced so it was never shown as an option.

Feel free to reach out directly if you'd like to learn more about Atlas.

Ken