TypeError: callback.apply is not a function after allowDiskUse

点点圈 提交于 2019-12-24 09:08:04

问题


I have a collection having 1Million documents... I have passed the option for allowDiskUse and now it is throwing error

TypeError: callback.apply is not a function

I have searched for this but could get the solution... Please help

const pictures = await Picture.aggregate([
      { $sort: { createdAt: -1 }},
      { $group: {
        _id: { $dateToString: { format: "%Y-%m-%d", date: "$createdAt" } },
        pictures: {
          $push: {
            _id: '$_id',
            image: '$image',
            time: { $dateToString: { format: "%H:%M:%S", date: "$createdAt" } }
          }
        }
      }},
      { $limit: 50 },
      { $project: {
        _id: false,
        createdAt: '$_id',
        pictures: '$pictures'
      }}
    ], { allowDiskUse: true })

Mongodb version - 3.6

Mongoose version - 5.0


回答1:


Because this is "mongoose". There is no "options" block on the aggregate() method in the Mongoose API. That's the source link and then the documentation. Note the returned <Aggregate> type.

That chains to allowDiskUse(true) as demonstrated in the documentation:

await Model.aggregate(..).allowDiskUse(true).exec()

You should really never need to use the option in most aggregations. Getting a warning message is usually an indicator that you are actually missing an index, or indeed any sane attempt to $match and filter down results.



来源:https://stackoverflow.com/questions/50756344/typeerror-callback-apply-is-not-a-function-after-allowdiskuse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!