I installed MongoDB on Yosemite using brew. I understand that the default storage location is /data/db. I'd like to change this to location /Volumes/Data/mongodb, so that when I run 'mongod', it will choose the databases in /Volumes/Data/mongodb by default. I tried editing the mongod.conf file, and I have
storage:
dbPath: /Volumes/Data/mongodb
However, whenever I run 'mongod', it gives me the message:
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
If I give mongod the --dbpath argument, it works fine, but I want it to work by default. Why does it appear that my mongod.conf file is not obeyed. Searching on google, it seems the conf file in installed in different locations depending on OS and install method. Running db.serverCmdLineOpts() gives:
{
"argv" : [
"/usr/local/opt/mongodb/bin/mongod",
"--config",
"/usr/local/etc/mongod.conf"
],
"parsed" : {
"config" : "/usr/local/etc/mongod.conf",
"net" : {
"bindIp" : "127.0.0.1"
},
"storage" : {
"dbPath" : "/Volumes/Data/mongodb"
},
"systemLog" : {
"destination" : "file",
"logAppend" : true,
"path" : "/usr/local/var/log/mongodb/mongo.log"
}
},
"ok" : 1
}
/Volumes
is sort of a reserved directory for mounting drives and bundles and shouldn't be worked on directly.Basically, there are two places to put MongoDB data in OS X. Sadly, neither brew nor MacPorts obey the File Hierarchy Standard*, which is also adopted by the BSD which is the foundation of OS X.
Since mongod is run from /usr/local
subtree, so this is our parent. But since variable data belongs to /var
we need to use the local tree there. So our base path for the data is /var/local/lib
. It is mongoldb data, so you can either put it into mongo
(because of the package basename) or mongodb
(because of the vendor name) or even mongod
(because of the daemon name). That's basically a matter of taste, but I'd stick with the vendor. So your dbpath would be /var/local/lib/mongodb
.
Put the data into your home directory.
Well, basically you can do what you want there, but in general I'd put data into a hidden directory (prefixed with a dot) so that it does not clutter your Finder. Something like $HOME/.mongodb
This solution isn't really clean, since the software will run from a public subtree and the data is stored in a user directory.
If you want to put your data into a volume or (sparse) bundle, simply create a symlink from the correct location to the volume, simply create a symlink instead of creating a directory. Example for solution 1:
sudo ln -s /Volumes/YourVolume /var/local/lib/mongodb
* Well, it is to argue that since MacPorts installs under /opt, it technically does (though imho it would rather belong to /usr/local in the first place)
AFAIK, mongod needs to be configured before working. There are 2 ways to specify configurations.
by command line arguments. which is the --dbpath parameter you added. for example:
mongod --dbpath /Volumes/Data/mongodb
By saying
I want it to work by default
I assume you mean you want to start daemon on system reboot. So the config file you are actually using is specified in the daemon script. For example in CentOS you can find daemon script in /etc/init.d/mongod
, where the line
CONFIGFILE="/etc/mongod.conf"
decides which config file you are using. So you may want to find your daemon script and check it first.
If this is not your situation, maybe you just downloaded mongodb from somewhere and unzipped it to your system, and you start mongodb with nothing but:
mongod
This way I guess the default location of mongod.conf is decided by the compiling parameters. Which means if you want to change it, you'll have to download the source code and compile it yourself.
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