0

I got this error:

app:tail-mongodb ERROR  Unhandled rejection:

z.cs.destroy is not a function

TypeError: z.cs.destroy is not a function
    at createChangeStream
(/Users/Olegzandr/codes/interos/read-from-mongodb/dist/main.js:74:18)
    at process.internalTickCallback (internal/process/next_tick.js:77:7)

here is my code:

import {ChangeStream} from "mongodb";

const z = {
    cs: null as ChangeStream,
 };

const createChangeStream = () => {

    if (z.cs) {
      z.cs.removeAllListeners();
      z.cs.destroy();
    }

    const changeStream = z.cs = d.db(dbName).collection(dbCollName).watch();

    changeStream.on('change', next => {

      if (!(next && next.fullDocument)) {
        log.warn('changed doc did not have fullDocument property, or was undefined:', next);
      }

      bun.handleIn(next.fullDocument || next);
    });

  };

seems weird that destroy() is not a valid method on the ChangeStream. Does anyone know the proper way to close a ChangeStream? The TypeScript typings say that this method is available, but I guess it is not.

  • I filed this related ticket: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/38857 –  Oct 03 '19 at 22:27
  • Have you tried the `close()` method as described in https://mongodb.github.io/node-mongodb-native/3.2/api/ChangeStream.html#close ? – kevinadi Oct 04 '19 at 00:36

0 Answers0