Below steps I followed to move the mongo db path from one location to other
1.Stop MongoDB services
sudo systemctl stop mongod.service
2.create a new directory in separate partition
mkdir /data/mongoDB/mongo
3.Make sure that mongod user has privileges to read / write from that directory
chown mongod:mongod -R /data/mongoDB
4.Copy the data folder of your old mongodb location to the new location
cp -R /var/lib/mongo/* /data/mongoDB/mongo/
5.create a copy of /etc/mongod.conf – for backup purpose
- change to new location of below variables in /etc/mongod.conf
path:
dbPath:
pidFilePath:
-
change the pid file location in mongod.service file
/usr/lib/systemd/system/mongod.service -
Run below command to reflect changes done
systemctl daemon-reload
8.Start mongodb services
sudo systemctl start mongod.service
Job for mongod.service failed because the control process exited with error code. See “systemctl status mongod.service” and “journalctl -xe” for details
NOTE-
- i checked the log file and there was no error registered after mongod shutdown
- i checked journalctl log file and below line appears
ERROR: child process failed, exited with error number 1**
To see additional information in this output, start without the “–fork” option.**
i used below command and mongodb started functioning
mongod --confog=/etc/mongod.conf
CAN YOU HELP HERE…AM I MISSING ANYTHING AND HOW CAN WE FIX mongod.service status???