【问题标题】:MongoError: Unrecognized pipeline stage name: '$changeStream'MongoError:无法识别的管道阶段名称:'$changeStream'
【发布时间】:2018-04-28 04:42:37
【问题描述】:

我们收到此错误:

   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,因此我们的某些数据可能缺少字段。

有谁知道如何缓解这个错误?

我们现在使用的是猫鼬版本5.0.16

【问题讨论】:

  • 基于official doc您只能针对副本集或分片集群打开更改流您是否满足要求?
  • 是的,我已连接到副本集
  • Docs 说变更流是New in version 3.6.
  • 我不确定猫鼬是否已经完全部署了该功能。根据文档,它应该用作生成器。但是,我真的对带有事件监听器的用例很感兴趣,因为它很新。
  • 哦,所以我需要使用 Mongo 3.6,而不是 Mongo 3.4

标签: node.js mongodb mongoose


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 2021-02-10
    • 2019-09-01
    • 2020-10-07
    • 2016-11-09
    • 1970-01-01
    相关资源
    最近更新 更多