MongoDB intrinsically support replication within the community edition itself. If you have worked with the MongoDB replicas before, you might have stumbled upon the error in secondary replicas.
In MongoDB, secondary replicas are the replicas which are only used for replication and no there transactional query can be performed on them. Sometimes, due to various reasons, secondary replicas may be stuck into recovering mode for indefinite period. Most of the time, These issues may occur when there is a sync difference of more than 24 hours between Primary and Secondary replicas or secondary data is corrupted and does not know how to perform sync.
Steps to fix the RECOVERING issue:
- Firstly, stop secondary replica service in which you are facing the problem.
sudo service mongod stop
- Then delete your data files.
sudo rm -rf /path/tp/db/data/directory
- Now, start the mongod service again.
sudo service mongod start
- Upon restarting, your MongoDB secondary replica will be in STARTUP2 state. This will force your secondary server to sync your databases again. Depending upon your database size, you should be able to see SECONDARY state in 30 – 60 minutes.