Data Directory Change in MongoDB
Mohammad Mizanur Rahman MBA(MIS) DU,MSCSE, BSCSE, PGD(PM), PCSM, OCP, CEH,
Sr. Manager SSD (Database Operation) (Oracle ||MongoDB|| MariaDB || Mysql || MS SQL || Postgresql || CassandraDB), Mentor and Author Ex-Lecturer - WUB, PUB Ex- Ericsson BD, Orbund LLC, Medical System Ltd. (KSA)
Stop MongoDB service
systemctl stop mongod
Create New Data Directory
mkdir /mongodata
Copy all the content from old data directory to new directory
cd /var/lib/mongo/
cp -rf * /mongodata/
Change the ownership of new directory with all copied content
chown -R mongod:mongod /mongodata/*
Rename the old data directory
mv /var/lib/mongo/ /var/lib/mongo_bkp
Change the data directory location in mongodb configuration file
vi /etc/mongod.conf
storage:
?dbPath: /mongodata/
?journal:
??enabled: true
Start MongoDB Service and check status
systemctl start mongod
systemctl status mongod