Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dont want to have to start mongod with `sudo mongod`

Tags:

macos

mongodb

I just downloaded mongodb onto my brandy new MacBookAir with OS X 10.9.5 by doing brew install mongodb.

I tried to run mongod from Terminal and it said "no /data/db" so I created it with sudo mkdir /data and sudo mkdir /data/db.

Running mongod now I get "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied" but I can run it perfectly fine with sudo mongod.

How can I make it so that I don't have to run mongod with sudo, but instead just as simply mongod?

(I had it like that on my last computer but do not remember what I did at all, and that computer was all messed up anyway.)

like image 491
tscizzle Avatar asked Oct 10 '14 17:10

tscizzle


People also ask

Why MongoDB is not opening?

We found that the reason for this error was the dbpath variable in /etc/mongodb. conf. Previously, the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with –config /etc/mongodb.

What is Mongod -- Dbpath?

By default, MongoDB listens for connections from clients on port 27017 , and stores data in the /data/db directory. On Windows, this path is on the drive from which you start MongoDB. For example, if you do not specify a --dbpath , starting a MongoDB server on the C:\ drive stores all data files in C:\data\db .

What is Mongod fork?

MongoDB is a source-available cross-platform document-oriented database program for high-volume storage. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. Forking a database cluster creates a new cluster from an existing cluster based on a specific point in time.


2 Answers

This worked for me:

sudo chmod -R 777 /data/db

then

sudo chown -R `id -u` /data/db

The -R makes the command recursive; I had previously tried both sudo chmod 777 /data/db and sudo chown `id -u` /data/db as instructed on other StackOverflow answers but they failed.

(PS I'm sorry I know this is a very old question but I found it while trying to look for an answer to my problem; and since I managed to solve it I thought I'd put this here for anyone in the future. Also I'm not sure which of those two commands made the difference, but it worked.)

like image 124
sabriele Avatar answered Sep 19 '22 05:09

sabriele


Simple Start it with

 mongod --dbpath ~/.mongodb/data --logpath ~/.mongodb/mongod.log --fork

after you did an

mkdir ~/.mongodb

The problem is that the default dbpath /data/mongodb was created for root.

Another option would be to do a

chown <your username here> -R /data/mongodb

And run mongod with the default paths.

As an alternative to running MongoDB directly under OSX, you might want to have a look atm202docker, which allows you to run MongoDB in a (thin) virtualized environment. There are other Docker images for MongoDB as well.

Disclaimer: I created the m202docker image, so I am propably biased

like image 21
Markus W Mahlberg Avatar answered Sep 21 '22 05:09

Markus W Mahlberg