How to work with changestreams for a collection?

Hi Team,

We want to implement changestreams for one of the collection and we have written the below code:

/home/mongodb/MONGODB_TESTDB/mongodb/mongodb/bin/mongo --host wikloh.hp.internet --port 27000 --authenticationDatabase=admin -u mongodb -p XXXXX < /home/mongodb/change_stream/change_stream.json >> /home/mongodb/change_stream/schema_creation_cs.log

cat change_stream.json

use KLP_MGMT_19
console.log("Watching for new changes  in this collection 'TestCounter' ...");[{
    $match: {
        //operationType: "update", //update|insert|delete|replace|invalidate
        fullDocument: "updateLookup", //default|updateLookup
    .on("change", (data) => {
    .on("error", (err)=>{

while (true) {

The code works well in nosqlbooster tool but same when i try to execute from server level getting below error:

switched to db KLP_MGMT_19
2020-09-03T06:00:52.217+0000 E QUERY    [js] ReferenceError: console is not defined :
2020-09-03T06:00:54.152+0000 I CONTROL  [main] shutting down with code:0

Please let me know hw to run the same via server and i also want to run this in background using nohup?


Hi @Mamatha_M

The error is because the mongo shell exposes a different API than the node driver. For example, console.log() is not a method the shell recognizes, as signified by the error message.

See for the API exposed by the shell with regard to change stream.

Roughly, what you want could be translated as such in the mongo shell:

cur =[], {fullDocument:'updateLookup'})
while(!cur.isExhausted()) {
  if (cur.hasNext()) {

Best regards,

Hi Kevin,

Thanks for the information.

I have heard MongoDB Kafka Connector also helps in changestreams to capture the CURD operation.

We have community version of mongo installed in our environment, So my query is will MongoDB Kafka Connector work for community edition or will it work only for Enterprise version?

Is there any other method by which we can work on changestreams?