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

Rails Duck
Rails Duck
8,545 Points

How to start a mongo server?

I've coded the whole js file as I'm supposed to and it works fine, but I get this error: MongoError: failed to connect to server [localhost:27017] on first connect. I decided to run the mongod command in another tab, but I got this as my answer:

2016-09-12T18:05:41.459-0400 I CONTROL [initandlisten] MongoDB starting : pid=14794 port=27017 dbpath=/data/db 64-bit host=PRIVATE_INFORMATION.PK5001Z 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] db version v3.2.9 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2h 3 May 2016 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] allocator: system 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] modules: none 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] build environment: 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] distarch: x86_64 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] target_arch: x86_64 2016-09-12T18:05:41.460-0400 I CONTROL [initandlisten] options: {} 2016-09-12T18:05:41.461-0400 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating 2016-09-12T18:05:41.461-0400 I CONTROL [initandlisten] dbexit: rc: 100

What is this supposed to mean?

2 Answers

Matt Milburn
Matt Milburn
20,786 Points

At the root level of your hard drive's file system, create the /data/db directory. Then make sure the directory and subdirectories are writeable with proper permissions.

sudo mkdir data data/db
sudo chmod 0755 data
sudo chmod 0755 data/db
sudo chown -R `id -u` data/db
Rails Duck
Rails Duck
8,545 Points

Thank you so much!

it looks like mongo is accessing "/data/db" directory, but there is no such directory

if its your first time starting mongo, you need to create that directory, and allow permissions to whatever user you are using to run mongod

take a look also in your /var/log/mongodb/mongod.log