代码之家  ›  专栏  ›  技术社区  ›  Ashh

typeerror:callback.apply不是allowdiskuse之后的函数

  •  1
  • Ashh  · 技术社区  · 6 年前

    我收藏了一百万份文件…我已经通过了 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

    Mongoose版本-5.0

    1 回复  |  直到 6 年前
        1
  •  3
  •   Neil Lunn    6 年前

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

    把链子拴在 allowDiskUse(true) 如文件所示:

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

    实际上,在大多数聚合中不应该使用该选项。得到一条警告消息通常是一个指示器,表明您实际上丢失了一个索引,或者确实是任何理智的尝试 $match 过滤结果。