You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MongoSH执行DocumentDB listChangeStreams命令时遇DBCommandCursor未定义错误

解决MongoSH中"ReferenceError: DBCommandCursor is not defined"问题

问题原因

DBCommandCursor是旧版MongoDB Shell(mongo)专属的API,而你使用的MongoDB Compass内置的是新版Mongo Shell(mongosh),该API在mongosh中已被移除,因此会触发未定义错误。

修正后的命令

无需手动实例化DBCommandCursor,直接使用db.runCommand返回的游标即可:

const cursor = db.runCommand({
  aggregate: 1,
  pipeline: [{$listChangeStreams: 1}],
  cursor: {}
}).cursor;
// 遍历游标查看所有变更流结果
cursor.forEach(doc => printjson(doc));

补充说明

AWS DocumentDB的官方文档可能基于旧版Mongo Shell编写,而mongosh对部分API做了简化调整。执行上述命令后,即可正常列出所有变更流。

内容的提问来源于stack exchange,提问作者outstacked

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 19:19:55