AWS DocumentDB如何开启变更流

问题描述:

AWS DocumentDB很多时候是需要开启变更流(change stream)的,那么如何开启,并且如何设置在DocumentDB中保留的时间呢?

问题解答 及 相关文档:

1. 文档[1]中有相关说明,用mongo shell登录DocumentDB以后,可以为所有集合,或者选定集合启用变更流:

//为选定的collection启用变更流: Enable change streams for the collection "foo" in database "bar"

db.adminCommand({modifyChangeStreams: 1,
    database: "bar",
    collection: "foo", 
    enable: true});

//Disable change streams on collection "foo" in database "bar"
db.adminCommand({modifyChangeStreams: 1,
    database: "bar",
    collection: "foo", 
    enable: false});

//为database "bar"内所有的collections 启用变更流:  Enable change streams for all collections in database "bar"
db.adminCommand({modifyChangeStreams: 1,
    database: "bar",
    collection: "", 
    enable: true});

//对所有的database都启用: Enable change streams for all collections in all databases in a cluster
db.adminCommand({modifyChangeStreams: 1,
    database: "",
    collection: "", 
    enable: true});

可以使用如下语句查看已经启用的变更流:

//列出集群的所有已启用的变更流: List all databases and collections with change streams enabled
cursor = new DBCommandCursor(db,
    db.runCommand(
        {aggregate: 1,
        pipeline: [{$listChangeStreams: 1}], 
        cursor:{}}));



//Determine if the database “bar” or collection “bar.foo” have change streams enabled
cursor = new DBCommandCursor(db,
  db.runCommand(
      {aggregate: 1,
       pipeline: [{$listChangeStreams: 1},
                  {$match: {$or: [{database: "bar", collection: "foo"},
                                  {database: "bar", collection: ""},
                                  {database: "", collection: ""}]}}
                 ],
      cursor:{}}));

2. 默认情况下,DocumentDB集群中变更流保留3小时(10800秒), 我们可以通过修改DocumentDB参数组中的change_stream_log_retention_duration 参数来修改保留时间,最长可以保留7天。

这个参数change_stream_log_retention_duration为动态参数,修改这个参数也是不需要重启DocumentDB集群的。

参考文档:

[1] 教程:将变更流与 Amazon DocumentDB 结合使用 - Amazon DocumentDB

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值