Most of Sysadmins don’t prefer to use / directory to store their files or databases. So if they have installed mongodb database server, by default it stored all data in /var/lib/mongo (version/os specific). In this tutorial, we will change mongodb default data path to other directory where we have attached a new disk (EBS volume in AWS).
Instruction’s to Change MongoDB Default Data Path:
1. Before making any changes, stop mongodb service
# service mongod stop
2. Now change the location of dbpath where MongoDB store all data. Edit mongodb configuration file /etc/mongodb.conf and update the value of dbpath variable with the new directory.
Change this:dbpath=/var/lib/mongo With:dbpath=/home/myuser/data/mongo
3. Now copy the old directory files to new location, like below command
# cp -ra /var/lib/mongo /home/myuser/data/mongo
4. Finally start the mongodb service using following command. Now MongoDB will start using new directory (/home/myuser/lib/mongo) as default data directory.
# service mongod start