Changing MongoDB data store directory

Mark Gill picture Mark Gill · May 11, 2011 · Viewed 261.8k times · Source

Until now I have not been specifying a MongoDB data directory and have had only one 30 GB primary partition.

I just ran out of space and added a new hard disk. How can I transfer my data (that is apparently in /var/lib/mongodb/) and configure MongoDB so that everything runs off of the new disk without affecting my existing installation?

Answer

Brendan W. McAdams picture Brendan W. McAdams · May 11, 2011

The short answer is that the --dbpath parameter in MongoDB will allow you to control what directory MongoDB reads and writes it's data from.

mongod --dbpath /usr/local/mongodb-data

Would start mongodb and put the files in /usr/local/mongodb-data.

Depending on your distribution and MongoDB installation, you can also configure the mongod.conf file to do this automatically:

# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb

The official 10gen Linux packages (Ubuntu/Debian or CentOS/Fedora) ship with a basic configuration file which is placed in /etc/mongodb.conf, and the MongoDB service reads this when it starts up. You could make your change here.