自学内容网 自学内容网

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


原文地址:https://blog.csdn.net/shiran0418/article/details/140645806

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!