【问题标题】:When Mongoose QueryStream emits an error event what is the state of the stream?当 Mongoose QueryStream 发出错误事件时,流的状态是什么?
【发布时间】:2013-08-01 09:06:28
【问题描述】:

我正在通过mongoose 向我的数据库打开一个流,并且想知道当它发出错误事件时流的状态是什么?这是否意味着正在流式传输的单个文档出现错误并且流将继续传输数据?或者这是否意味着整个流出现错误并且流现在已损坏/关闭?

这是来自 Mongoose 文档的示例代码:

var stream = Model.find().stream();

stream.on('data', function (doc) {
  // do something with the mongoose document
}).on('error', function (err) {
  // What state is the stream here?????
}).on('close', function () {
  // the stream is closed
});

【问题讨论】:

    标签: javascript node.js mongodb mongoose


    【解决方案1】:

    对于一般的Streams'error' 事件通常意味着流已停止并且不会再发射'data'

    发出'error' 通常等同于throw statement,它会中断应用程序流程。而且,类似于try...catch.on('error') 回调是一种处理错误的方法。

    对于Domains'error' 甚至可能由throw 触发。

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 2017-02-25
      • 1970-01-01
      相关资源
      最近更新 更多