MongoDB Data directory /data/db not found [duplicate]

When I try to run Mongod in terminal I got this message :

2015-05-14T17:33:04.554+0700 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2015-05-14T17:33:04.554+0700 I CONTROL  [initandlisten] dbexit:  rc: 100

and running mongo command :

MongoDB shell version: 3.0.3
connecting to: test
2015-05-14T17:34:26.679+0700 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-05-14T17:34:26.681+0700 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed

I Have tried to change permision in /var/lib/mongodb and /var/log/mongodb, but still doesnt work, and I tried to uninstall and install mongodb again, but still the same problem exist. Anyone could help? Thanks

I'm using Ubuntu 14.04 LTS 64 bit


Solution 1:

MongoDB needs data directory to store data. Default path is /data/db

When you start MongoDB engine, it searches this directory which is missing in your case. Solution is create this directory and assign rwx permission to user.

If you want to change the path of your data directory then you should specify it while starting mongod server like,

mongod --dbpath /data/<path> --port <port no> 

This should help you start your mongod server with custom path and port.