Explain MongoDB data restore and synchronization solution in detail

  • 2020-09-16 07:50:48
  • OfStack

How can mongodb data be restored and synchronized to other systems? Once we understand the principles of database logging, everything is as simple as that

oplog principle

The Oplog. rs table type is Capped Collections

- Table type:

Capped collections is very fast at inserting, roughly as fast as writing to disk, and supports efficient query operations in insert order. Capped collections is fixed in size and works much like a ring buffer (circular buffers), overwriting the first data to be inserted when there is not enough space left.

Advantage:

Capped collections is characterized by efficient insertion and retrieval, so it is best not to add additional indexes to Capped collections, otherwise the insertion speed will be affected.

Insert fast: No index

natural [insertion order] /∗ Default only supports return results in natural order (insert order) Cappedcollections can be used with "role="presentation" > natural [insert order] / Default only supports return results in natural order (insert order) Cappedcollections can use natural [insert order] / Default only supports return results in natural order (insert order) Cappedcollections can use the natural operator to return results in either positive or negative order in insert order

*/
To ensure insert performance, Oplog does not allow additional index creation.

Capped collections can be used for the following scenarios:

Storage log: the first-ES57en-ES58en-ES59en feature of Capped collections just meets the storage order of log events;

Cache small amounts of data: Because caching is characterized by more reads and less writes, indexes can be used appropriately to improve read speed.

Limitations:

If you update the data, you need to index it to prevent collection scan;

When updating data, the size of the document cannot be changed. For example, if the attribute name is 'abc', it can only be changed to a 3-character string, otherwise the operation will fail.

Data deletion is not allowed. If deletion is absolutely necessary, it can only be drop collection

db[‘oplog.rs'].find({}).sort({$natural: -1})

Oplog is a special TYPE of Capped collections, which is special in that it is system level Collection, which records all database operations and relies on Oplog for data synchronization between clusters. The full name of Oplog is ES87en.oplog.rs, located under the local data.

conclusion


Related articles: