Mongoose Aggregate:空结果永远不会触发回调

时间:2014-06-05 14:10:13

标签: mongodb mongoose aggregation-framework

我正在使用mongoose并在mongoshell中定义了一些聚合。 有时,匹配条件会过滤掉所有数据。尽管如此:Mongoose没有回拨。

这很容易重复,例如

Contract.aggregate( {
$match:{user:'dummydata'}}, 
function (err, result) {
  console.log('this never happens');
});

如果我输入现有用户ID,则会调用回调。 如果我使用非existend用户id,则永远不会调用回调。 但我怎么知道发生了什么?

1 个答案:

答案 0 :(得分:0)

我偶然发现,需要第二次“无结果”回调。

所以正确的解决方案是

Contract.aggregate( {
    $match:{user:'dummydata'}
}, 
function (err, result) {
      console.log('this never happens');
}, 
function(err,result) {
 console.log('Crap there is no result');
});