22

I do gave this path for data/db

/usr/local/Cellar/mongodb/3.2.6/data/db

The following step was made in order to create a bound to mongodb folder

sudo mongod --directoryperdb --dbpath /usr/local/Cellar/mongodb/3.2.6/data/db --logpath /usr/local/Cellar/mongodb/3.2.6/log/mongodb.log --logappend -rest

When initialize sudo mongod in terminal the following error appears:

2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] MongoDB starting : pid=8107 port=27017 dbpath=/data/db 64-bit host=iMac-Krystyna-2.local
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] db version v3.2.6
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2h  3 May 2016
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] allocator: system
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] modules: none
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] build environment:
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten]     distarch: x86_64
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] options: {}
2016-06-08T14:45:06.970+0200 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2016-06-08T14:45:06.970+0200 I CONTROL  [initandlisten] dbexit:  rc: 100

Can you please explain what is wrong and maybe show some common practice in order to work correctly with MongoDB?

volna
  • 2,452
  • 4
  • 25
  • 61

6 Answers6

33

You need to create this directory as root

Either you need to use sudo , e.g. sudo mkdir -p /data/db

Or you need to do su - to become superuser, and then create the directory with mkdir -p /data/db

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
Zamba
  • 480
  • 6
  • 10
12

You can also give this command sudo mongod --dbpath=/var/lib/mongodb. Open another terminal and run your mongod.

swati_munda
  • 651
  • 6
  • 6
9

It worked for me. try: sudo service mongod start

Capt
  • 261
  • 4
  • 11
5

I had the same issue. This worked for me:

sudo mongod --dbpath ~/data/db
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
1

In my case, an incorrect conf file caused Mongo to use default settings (i.e. using /data/db as the storage path. Because /data/db doesn't exist, it complains.

Possible sources of incorrect config include:

(1) Unquoted strings. E.g. storage.dbPath should be "some/path" (2) Incorrect bindIp. It seems an array of IPs is not supported.

So my fix was simply to use quoted strings in those places: storage: dbPath: "/some/path" net: bindIp: "127.0.0.1"

Note: My "/some/path" has permissions drwxr-xr-x (755) and is owned by mongodb/mongodb. And it works.

RavenMan
  • 1,807
  • 1
  • 15
  • 27
-3

MongoDB try to find data/db folder under root directory of your system. try to create folder under /data/db.

Girdhari Agrawal
  • 375
  • 3
  • 18