TypeError:callback.apply不是allowDiskUse之后的函数

问题描述:

我有一个包含一百万个文档的集合...我已经通过了 allowDiskUse 的选项,现在它抛出错误

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

TypeError:callback.apply不是函数

我已经搜索过了,但是可以得到解决方案...请帮助

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版本- 3.6

Mongodb version - 3.6

猫鼬版本-5.0

因为这是猫鼬。在 aggregate()方法在猫鼬API中。这是源链接,然后是文档。请注意,返回的 < Aggregate> 类型。

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.

链接到 allowDiskUse(true) 如文档所示:

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

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

您实际上,绝不需要在大多数聚合中使用该选项。收到警告消息通常表明您实际上缺少索引,或者实际上是对 $ match 并过滤结果。

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.