Ash*_*shh 1 mongoose mongodb node.js mongodb-query aggregation-framework
我有一个包含 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 })
Run Code Online (Sandbox Code Playgroud)
Mongodb 版本 - 3.6
猫鼬版本 - 5.0
因为这是“猫鼬”。Mongoose API 中的aggregate()方法没有“选项”块。那是源链接,然后是文档。注意返回的类型。<Aggregate>
allowDiskUse(true)如文档中所示,链接到:
await Model.aggregate(..).allowDiskUse(true).exec()
Run Code Online (Sandbox Code Playgroud)
您真的永远不需要在大多数聚合中使用该选项。收到警告消息通常表明您实际上缺少索引,或者实际上是任何理智的尝试$match和过滤结果。