gpt4 book ai didi

javascript - Mongoose 回调应用不是函数

转载 作者:行者123 更新时间:2023-11-30 20:44:50 24 4
gpt4 key购买 nike

我更新到 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

});

最佳答案

尝试将 sortlimit 链接方法更改为聚合调用中的阶段:

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
});

关于javascript - Mongoose 回调应用不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48833079/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com