MongoError:无法识别的管道阶段名称:'$ changeStream'

时间:2018-04-23 20:02:33

标签: node.js mongodb mongoose

我们收到此错误:

   MongoError: Unrecognized pipeline stage name: '$changeStream'
        at queryCallback (/Users/alexamil/WebstormProjects/nabisco/cdt-now/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:244:25)
        at /Users/alexamil/WebstormProjects/nabisco/cdt-now/node_modules/mongodb/node_modules/mongodb-core/lib/connection/pool.js:544:18
        at _combinedTickCallback (internal/process/next_tick.js:131:7)
        at process._tickDomainCallback (internal/process/next_tick.js:218:9)

我们有这个文件,它将更新我们服务器上的一些缓存:

'use strict';

import caches = require('../../models/caches');

import {Phase, Acquisition, Category, FunctionalGroup, Role, User, Workstream} from "../../models";

Acquisition.watch().on('change', function (c) {
  console.log('acq change:', c);
});

Category.watch().on('change', function (c) {
  console.log('category change:', c);
});

FunctionalGroup.watch().on('change', function (c) {
  console.log('functional team change:', c);
});

Role.watch().on('change', function (c) {
  console.log('role change:', c);
});

User.watch().on('change', function (c) {
  console.log('user change:', c);
});

Workstream.watch().on('change', function (c) {
  console.log('workstream change:', c);
});

我们正在从Mongo 2.6迁移到Mongo 3.4,因此我们的一些数据可能缺少字段。

有谁知道如何缓解此错误?

我们现在使用的是mongoose版本5.0.16

1 个答案:

答案 0 :(得分:0)

Change streams are new in MongoDB 3.6.如果在连接到较旧版本的MongoDB服务器时在mongoose中使用MyModel.watch(),则会出现此错误。