对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

Oplog 访问权限

注意

This page applies to Atlas Infinite clusters and Atlas Core clusters. On an Atlas Infinite cluster, you can read the oplog collection as described on this page, but you can't set an oplog size. The collection serves change streams and some internal functions rather than replication, which the storage layer handles. To learn how the oplog behaves on an Atlas Infinite cluster, see Oplog on Atlas Infinite clusters.

oplog 是一个特殊的固定大小集合,它记录修改数据库中存储的数据的操作。

You must precede a $regex query on an oplog in a Free cluster or a Flex cluster with a carat (^). Otherwise, the following error occurs:

MongoServerError: Oplog ns RegEx queries must begin with ^

要访问 oplog,数据库用户必须具有 local 数据库的读取权限。要创建对 local 具有读取权限的用户:

1
  1. 如果尚未显示,请从导航栏上的 Organizations 菜单中选择包含项目的组织。

  2. 如果尚未显示,请从导航栏的 Projects 菜单中选择您的项目。

  3. 在侧边栏中,单击 Security 标题下的 Database & Network Access。

The Database & Network Access page displays after you complete the preceding steps.

2
  1. 如果尚未显示,请单击 Database Users(数据库用户)标签页。

  2. 单击 Add New Database User,然后输入用户名,如 oploguser。

  3. 单击 Grant Specific Privileges,然后选择 read 角色和 local 数据库。这会限制用户对 local 数据库进行读取操作。

  4. 输入密码并单击 Add User 。

  1. Connect to your cluster with the mongosh, using the credentials of the new database user with access to the local database.

  2. 切换到 local 数据库。

    > use local
  3. oplog 集合名称为 oplog.rs。数据库写操作按日期顺序记录,并带有一个时间戳字段和一个挂钟字段。

    时间戳字段包含一个整数,表示自纪元以来的秒数。

注意