Hi Team,
We want to implement changestreams for one of the collection and we have written the below code:
cat schema_creation_cs.sh
#!/bin/bash
/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' ...");
db.TestCounter.watch([{
$match: {
//operationType: "update", //update|insert|delete|replace|invalidate
}
}],
{
fullDocument: "updateLookup", //default|updateLookup
})
.on("change", (data) => {
console.log(tojson(data))
})
.on("error", (err)=>{
console.error(err)
});
while (true) {
sleep(1000)
}
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 :
@(shell):1:1
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?
Regards