Does the secondary copy the oplog from primary, save it in the local file system and then apply?

How does the secondary replicate the data?
Does the secondary copy the oplogs from primary and save it in it’s oplogs locally in it’s file system and then apply? Or when the secondary copy the oplog from primay and it keeps in it’s memory and then apply, when applying it write to it’s oplogs? Can anyone clarify?

Hello @Pirathapan_09074,

First, know what is an oplog - as this is the most important aspect of the replication.

The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in the databases. When you start a replica set member for the first time, MongoDB creates an oplog for that member. The oplog is a database collection and all collection data is stored on the disk, in the database folder specified by the dbpath.

What happens with replication and oplog?

  • MongoDB applies database operations on the primary and then records the operations on the primary’s oplog.
  • The secondary members then copy the oplog entries and apply these operations (from the oplog) on their data in an asynchronous process.

All replica set members contain a copy of the oplog in the collection. You can query the oplog collection when connected to a replica set member, as follows:

> use local

Hi @Pirathapan_09074,

I hope the response of the @Prasad_Saya, clarifies your doubt.

If you want, you can read more about the Replica Set Oplog here.

Let us know if you still have any questions.


Thank you @Prasad_Saya and @Kushagra_Kesav.
This is where I had the confusion. The secondary members then copy the oplogs entries and apply these operations).
wording (from the oplogs) secondary applies the operation to data, now it clarifies .

How can we verify the operation from oplogs got applied to data in secondary? Is there any sequence number/ or unique id with the operation in oplogs can be verified against in the data in the secondary just incase the server got re-booted while applying?


1 Like

Hello @Pirathapan_09074, you can get status of the replica set using the information from the oplog with the db.getReplicationInfo() command. The output document has various fields with diagnostic information about the replication.

1 Like

Hi @Pirathapan_09074,

Thanks for asking.

Here @Prasad_Saya, answer your question.

Read here

I hope it clarifies your doubt.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.