Docs 菜单
Docs 主页
/
MongoDB Manual
/ / / /

changeStreamOptions

在此页面上

  • 定义
  • 语法
  • 参数字段
  • 行为
  • 例子
changeStreamOptions

6.0 版本中的新功能

适用于 mongodmongos

包含change stream配置选项的对象。

您只能在mongos或副本集主节点上设置changeStreamOptions 。 该值在集群范围内设置。

要为部署设置changeStreamOptions ,请对admin数据库运行以下命令:

db.adminCommand( { setClusterParameter: { changeStreamOptions: <value> } } )

要查看changeStreamOptions集群参数的当前值,请对admin数据库运行以下命令:

db.adminCommand( { getClusterParameter: "changeStreamOptions" } )
changeStreamOptions.preAndPostImages.expireAfterSeconds

6.0 版本中的新功能

默认:关闭

控制change stream帖子和前映像的保留策略。前像和帖子像分别是文档修改之前和之后的文档版本。expireAfterSeconds控制 MongoDB 保留前像和帖子的时间。

expireAfterSecondsoff 时,可使用默认保留策略:将保留前像和后像,直到从 oplog 中删除对应的变更流事件。

要设置前像和帖子像的最短保留时间,请为expireAfterSeconds指定一个整数值。

重要

Services that use change streams, including Triggers and Device Sync, might rely on the availability of pre-image data. If you set expireAfterSeconds too low, you may increase the risk of interrupting sync or triggers processing.

为前像设置expireAfterSeconds时,请确保:

  • 指定一个不低于服务的典型变更流延迟的值。

  • 添加缓冲时间,以允许在oplog数据丢失之前手动恢复服务。

如果从 oplog 中删除变更流事件,则无论changeStreamOptions.preAndPostImages.expireAfterSeconds指定的保留时间如何,相应的前映像和后映像也会被删除。

以下示例将change stream中前像和帖子的保留时间设置为100秒:

db.runCommand( {
setClusterParameter: {
changeStreamOptions: { preAndPostImages: { expireAfterSeconds: 100 } }
}
} )

后退

auditConfig