0

我收到了这个错误:

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)

这是我的代码:

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);
    });

  };

似乎很奇怪,destroy() 不是 ChangeStream 上的有效方法。有谁知道关闭 ChangeStream 的正确方法?TypeScript 打字说这个方法是可用的,但我猜它不是。

4

0 回答 0