Error using changeStream with Node.js

my version info:

MongoDB shell version v4.2.14
node --version

I am not doing anything creative - simply trying to follow the tutorial given below (by mongo):

Apparently .watch function is in mongo since version 3.0 – anothe rplace i read it has been there since 3.6 but i have ver4.2.14 - so i should be good there.

For node.js – i have version 14.18.0 (latest perhaps)

I am getting this error while trying to run the code present in the tutorial.

There is no issue with my db connection as i have tried it out separately.
the error is as follows:

      throw er; // Unhandled 'error' event

MongoServerError: Unrecognized pipeline stage name: '$changeStream'
    at MessageStream.messageHandler (/home/directorypath/node_modules/mongodb/lib/cmap/connection.js:467:30)
    at MessageStream.emit (events.js:400:28)
    at processIncomingData (/home/directorypath/node_modules/mongodb/lib/cmap/message_stream.js:108:16)
    at MessageStream._write (/home/directorypath/node_modules/mongodb/lib/cmap/message_stream.js:28:9)
    at writeOrBuffer (internal/streams/writable.js:358:12)
    at MessageStream.Writable.write (internal/streams/writable.js:303:10)
    at Socket.ondata (internal/streams/readable.js:731:22)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)
    at readableAddChunk (internal/streams/readable.js:267:9)
Emitted 'error' event on ChangeStream instance at:
    at closeWithError (/home/directorypath/node_modules/mongodb/lib/change_stream.js:356:22)
    at processError (/home/directorypath/node_modules/mongodb/lib/change_stream.js:449:12)
    at Readable.<anonymous> (/home/directorypath/node_modules/mongodb/lib/change_stream.js:365:33)
    at Readable.emit (events.js:400:28)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  ok: 0,
  code: 16436

Hi @Syed_Naqvi and welcome!

It’s been a while since you posted the question, have you found the solution yet ?

Could you provide answers to the following:

  • Did you receive the error when you first try to execute node changeStreams.js in the tutorial ?
  • Where is your MongoDB cluster deployed ? i.e. Atlas, locally, etc
  • As posted above you are using mongo shell version 4.2.14, could you tell us what is your MongoDB server version ?
  • Which version of mongodb NPM package did you use ? could you please post the content of package.json ?