【问题标题】:Mongoose Aggregate: Empty results never trigger the callbackMongoose Aggregate:空结果永远不会触发回调
【发布时间】:2014-07-26 13:56:04
【问题描述】:

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

这很容易重现,例如

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

如果我输入一个现有的用户 ID,回调就会被调用。 如果我使用不存在的用户 ID,则永远不会调用回调。 但是我怎么知道发生了什么?

【问题讨论】:

    标签: mongodb mongoose aggregation-framework


    【解决方案1】:

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

    所以正确的解决方案是

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

    【讨论】:

      猜你喜欢
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      • 2014-07-20
      • 1970-01-01
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 2019-10-24
      相关资源
      最近更新 更多