How can I change the default mongodb location?

I have installed MongoDB on Yosemite using brew. I understand that the default storage location is / data / db. I would like to change this to location / Volumes / Data / mongodb so that when I start mongod it will select the databases in / Volumes / Data / mongodb by default. I have tried editing mongod.conf file and I have

storage:
  dbPath: /Volumes/Data/mongodb

      

However, whenever I start "mongod" it gives me a 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 seem like my mongod.conf file is not being honored. Searching on google it looks like the conf file is installed in different places depending on OS and installation 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
}

      

+3


source to share


2 answers


Notes

  • The path must exist. It is not automatically generated.
  • /Volumes

    is a kind of reserved directory for installing discs and packs and should not be handled directly.
  • If you are using volumes or a (sparse) package, you need to make sure it is installed at boot, or you need to do it manually before starting MongoDB.

Basically, there are two places to put MongoDB data on OS X. Unfortunately, neither brew nor MacPorts obey the File Hierarchy Standard *, which is also accepted by BSD, which is the foundation of OS X.

Solution 1: You want your data to be available to all OS X users

Since mongod is launched from a subtree /usr/local

, so this is our parent. But since the variable data belongs /var

, we need to use the local tree there. Thus, our base path for data /var/local/lib

. This is mongoldb data, so you can put it in mongo

(because of the base name of the package) or mongodb

(because of the vendor name) or even mongod

(because of the daemon name). This is mostly a matter of taste, but I'll stick with the seller. This way your dbpath will be /var/local/lib/mongodb

.

Solution 2: you will access the data

Place the data in your home directory.



Well, basically you can do what you want, but in general I would put the data in a hidden directory (prefixed with a period) so that it doesn't clutter up your Finder. Something like$HOME/.mongodb

This solution is not very clean as the software will run from an open subtree and the data is stored in the user's directory.

Extension for both solutions

If you want to put your data in volumes or a (sparse) package, just create a symlink from the correct location in that, just create a symlink instead of creating a directory. Solution example 1:

sudo ln -s /Volumes/YourVolume /var/local/lib/mongodb

      

* Well, one has to argue that since MacPorts is installed under / opt this is technically (although imho will most likely be owned by / usr / local)

+4


source


AFAIK, mongod needs to be configured before getting started. There are two ways to specify configurations.

  • by command line arguments. which is the added -dbpath option. eg:

    mongod --dbpath /Volumes/Data/mongodb
    
          

  • specifying the configuration file. Usually, if you install the source code, it comes with one in /etc/mongod.conf (depends on different Linux distributions). Where you can specify all parameters in it.

Speaking

I want it to work by default

I am assuming that you want you to start the daemon on system reboot. So the config file you are using is listed in the daemon script. For example, on CentOS, you can find a daemon script at /etc/init.d/mongod

where the line



CONFIGFILE="/etc/mongod.conf"

      

determines which config file you are using. So you can find your script daemon and test it first.

If this is not your situation, it is possible that you just downloaded mongodb and unpacked it on your system, and you started mongodb with just:

mongod

      

Thus, I am assuming the default location of mongod.conf is determined by compilation options. This means that if you want to change it, you will have to download the source code and compile it yourself.

+3


source







All Articles