【问题标题】:TypeError: callback.apply is not a function after allowDiskUseTypeError:callback.apply 不是 allowDiskUse 之后的函数
【发布时间】:2018-11-18 06:16:02
【问题描述】:

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

TypeError: callback.apply is not a function

我已经搜索过这个但可以得到解决方案...请帮助

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

猫鼬版本 - 5.0

【问题讨论】:

    标签: node.js mongodb mongoose mongodb-query aggregation-framework


    【解决方案1】:

    因为这是“猫鼬”。 aggregate() 方法 in the Mongoose API 上没有“选项”块。这是源链接,然后是the documentation。注意返回的<Aggregate> 类型。

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

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

    您应该永远不需要在大多数聚合中使用该选项。收到警告消息通常表明您实际上缺少索引,或者实际上是任何理智的尝试$match 并过滤掉结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 2018-11-28
      • 2015-12-29
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多