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.)
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.
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 .
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.
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.)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With