TypeError:callback.apply不是allowDiskUse之后的函数 [英] TypeError: callback.apply is not a function after allowDiskUse

查看:85
本文介绍了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.

这篇关于TypeError:callback.apply不是allowDiskUse之后的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆