Mongodb – Syncing data from primary member to secondary after election

backupdata synchronizationmongodbmongodb-3.2replication

Maybe this is kind a stupid question but, I'm novice in configuring replication and I need to clear something before makeing anything else.
Moment ago I configured replica set with 3 members in it. It's all working well but I think I don't understand the part about copying data from primary to secondary member of replica set after new election.

Let's say I made one collection in my primary member, after that kill instance of primary member, election has been made and now I have new instance as primary member on example –port 27018.
What happend with all data on first instance which I killed? Do I need to make mongodump? Do I need to use some sync method for instant syncing or read the oplog and how to do that? Beacause, I tought that if I made an replSet, and turn on all three instances which are connected, all of them will listening the same oplog and after election update the database, or I'm completly wrong about that and I'm clearly missing some things?

Thank you!

Best Answer

It depends how far behind it fell and what status you have it in your config file at the time of resync.

Basically if you've been down so long that it can't catch up with the OpsLog or the OpsLog no longer has the transactions it needs due to it being removed over time you'll want to resync yourself.

Check out the docs for your version:

Restart the mongod with an empty data directory and let MongoDB’s normal initial syncing feature restore the data. This is the more simple option but may take longer to replace the data.

See Procedures.

Restart the machine with a copy of a recent data directory from another member in the replica set. This procedure can replace the data more quickly but requires more manual steps.

See Sync by Copying Data Files from Another Member.

Let us know if you have more questions. Good luck. Test test test!