简体   繁体   English

获取集合操作序列MongoDB

[英]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.也许我可以通过阅读opLog来解决这个问题。

  1. Is it the correct solution to use opLog?使用 opLog 是正确的解决方案吗?
  2. Does oplog contains records for all db, not slited by collections? oplog 是否包含所有数据库的记录,而不是被集合分割?

Use MongoDB v4.2使用 MongoDB v4.2

Is it the correct solution to use opLog?使用 opLog 是正确的解决方案吗?

The oplog format is internal and designed to support replication. oplog 格式是内部的,旨在支持复制。 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.您应该改用基于 oplog 的Change Streams API ,它允许订阅集合、数据库或部署级别的数据更改。 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.与直接 oplog 访问不同,变更流有一个文档化的 API,可以通过访问控制进行限制,可以对流输出执行一些过滤和修改,并且可以扩展以支持副本集和分片集群。 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. MongoDB 4.0+ 中的更改流允许您指定startAtOperationTime以在特定时间点打开游标。 If the specified starting point is in the past, it must be in the time range of the oplog.如果指定的起点在过去,则必须在oplog的时间范围内。

Does oplog contains records for all db, not slited by collections? oplog 是否包含所有数据库的记录,而不是被集合分割?

The oplog is a capped collection containing a rolling history of all data changes for a replica set or shard. oplog 是一个有上限的集合,包含副本集或分片的所有数据更改的滚动历史记录。 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.上限集合方面意味着 oplog 具有有限的历史窗口:一旦达到最大 oplog 大小,最旧的条目将被删除,以便为新文档腾出空间。 The local.oplog.rs data is not filtered by collection or namespace. local.oplog.rs数据未按集合或命名空间过滤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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