amazon-web-servicesaws-documentdbaws-documentdb-mongoapi

DocumentDB listchangestreams


Following the AWS documentation we are trying to list all change streams using the command

cursor = new DBCommandCursor(db,
    db.runCommand(
        {aggregate: 1,
            pipeline: [{$listChangeStreams: 1}], cursor:{}}));

We are running this in the MongoSH provided in the MongoDB Compass application. But we are getting an error that says: "ReferenceError: DBCommandCursor is not defined". I am completely lost on how to solve this.


Solution

  • Try running the command without wrapping it in a DBCommandCursor:

    db.runCommand(
        {aggregate: 1,
            pipeline: [{$listChangeStreams: 1}], cursor:{}});
    

    Your change streams will be listed in the cursor.firstBatch array of the results.

    If you need to see more results (i.e., if the default batch size is too small), you can use the batchSize parameter:

    db.runCommand(
        {aggregate: 1,
            pipeline: [{$listChangeStreams: 1}], cursor:{"batchSize": 1000}});
    

    Be sure to connect to the cluster endpoint (or directly to the primary instance endpoint), otherwise you will get this error:

    MongoServerError: Aggregation stage not supported: '$listChangeStreams'