简体   繁体   中英

Mongoose callback apply is not a function

I updated to mongoose version 4.10.5 , but for some reason, now my aggregate is failing and getting the following error:

   \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)

What do i need to edit to make this work again?

The code that is beeing executed:

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

});

Try changing the sort and limit chaining methods, to stages in the aggregate call:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM