简体   繁体   中英

Get collection operation sequence MongoDB

I need to get sequence of collection operation in runtime by daemon to write it to system similar to message broker. Necessary ability to read history from a specified position

Probably I can solve this problem by reading opLog.

  1. Is it the correct solution to use opLog?
  2. Does oplog contains records for all db, not slited by collections?

Use MongoDB v4.2

Is it the correct solution to use opLog?

The oplog format is internal and designed to support replication. As an internal format, it is subject to change between major server releases and not straightforward to consume.

You should instead use the Change Streams API which builds on the oplog and allows subscribing to data changes on a collection, database, or deployment level. Unlike direct oplog access, change streams have a documented API, can be limited with access control, can perform some filtering and modification of stream output, and can scale to support replica sets as well as sharded clusters. Change streams can also be resumed if interrupted.

Necessary ability to read history from a specified position

Change streams in MongoDB 4.0+ allow you to specify startAtOperationTime to open the cursor at a particular point in time. If the specified starting point is in the past, it must be in the time range of the oplog.

Does oplog contains records for all db, not slited by collections?

The oplog is a capped collection containing a rolling history of all data changes for a replica set or shard. The capped collection aspect means that the oplog has a limited history window: once the maximum oplog size is reached, the oldest entries are removed to make room for new documents. The local.oplog.rs data is not filtered by collection or namespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM