Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mongoose回调应用不是一个函数_Javascript_Mongodb_Mongoose_Aggregate - Fatal编程技术网

Javascript Mongoose回调应用不是一个函数

Javascript Mongoose回调应用不是一个函数,javascript,mongodb,mongoose,aggregate,Javascript,Mongodb,Mongoose,Aggregate,我已更新到mongoose版本4.10.5,但由于某些原因,现在我的聚合失败,并出现以下错误: \node_modules\mongoose\lib\utils.js:214 throw error; ^ TypeError: callback.apply is not a function at utils.promiseOrCallback.cb (C:\Users\Malin\Desktop\gameserver\node_mod

我已更新到mongoose版本
4.10.5
,但由于某些原因,现在我的聚合失败,并出现以下错误:

   \node_modules\mongoose\lib\utils.js:214
            throw error;
            ^

TypeError: callback.apply is not a function
  at utils.promiseOrCallback.cb (C:\Users\Malin\Desktop\gameserver\node_modules\mongoose\lib\aggregate.js:693:14)
    at Object.promiseOrCallback (C:\Users\Malin\Desktop\gameserver\node_modules\mongoose\lib\utils.js:211:14)
    at Aggregate.exec (C:\Users\Malin\Desktop\gameserver\node_modules\mongoose\lib\aggregate.js:690:16)
    at Function.aggregate (C:\Users\Malin\Desktop\gameserver\node_modules\mongoose\lib\model.js:2809:13)
我需要编辑什么才能使它再次工作

正在执行的代码:

return Account.aggregate(
        // Limit to relevant documents and potentially take advantage of an index
        { $match: {
            haveusername: true,
        }},

        { $project: {
            total: { $add: ["$cash", "$bank"] }
        }}
    ).sort({total: -1}).limit(10).then(function (richest) {
//something else here

});

尝试将
排序
限制
链接方法更改为聚合调用中的阶段:

return Account.aggregate(
        // Limit to relevant documents and potentially take advantage of an index
        { $match: {
            haveusername: true,
        }},
        { $project: {
            total: { $add: ["$cash", "$bank"] }
        }},
        { $sort: {total: -1} },
        { $limit : 5 }
    ).then(function (richest) {
        //something else here
    });

排序
限制
作为聚合管道中的一个阶段,怎么样?是的,这可能是个问题,但我对聚合atm不是很在行。让我发布一个我将如何做的答案(但我不确定
然后
链接).MongooseError:Mongoose 5.x不允许将运算符的排列传递给
Model.aggregate()
。不要使用
Model.aggregate({$match},{$skip})
,而是使用
Model.aggregate([{$match},{$skip}])