We have 3 members replica set of mongo db (MongoDB server version: 4.2.9). one of the member (secondary) is running on default storage db path and this storage getting nearly full. We need to change path of that specific secondary node of 3-member replica set. I am new to mongodb. I need your expertise to accomplish this task.
MongoDB server version: 4.2.9 OS Version: CentOS Linux release 7.8.2003 (Core).
Regards,
Stop the mongod service:
mongo --host xxxx --port yyyy
use admin
db.shutdownServer()
Copy the data from old location to the new location:
cp -R /oldPath/ /newPath/
Change in the /etc/mongodb.conf the dbPath to point to the new location.
Start the mongodb service.
Same like option 1) , just ommit the point 2) just you will need to wait abit until the member init sync ( copy the data ) from the other members , it depends on data size and compression.
From the PRIMARY member add another member on that will use the new path:
rs.add("newMember:XXXX")
Wait until the new member init sync.
Remove the old SECONDARY member:
rs.remove("oldMember:YYYY")
Clean the old files and configuration. ( small disadvantage with this option that you will need to change the port for the new member if on the same host )
Option 2) seems best suitable for your case ...