我正在使用聚合管道来清除数据库集合中的重复数据.但即使在设置{ allowDiskUse: true }
之后,它仍抛出以下错误.
Err: "MongoServerError: PlanExecutor error during aggregation :: caused by :: Exceeded memory limit for $group, but didn't allow external spilling; pass allowDiskUse:true to opt in"
个
objective
是在保留数据库中的第一个条目之后删除所有重复项(具有相同startTime的相同phoneNumber).
以下是我的销售渠道:
let pipeline = [
{
$group: {
_id: {
phoneNumber: "$details.phoneNumber",
startTime: "$details.startTime",
},
docs: { $push: "$$ROOT" },
count: { $sum: 1 },
},
},
{
$match: {
count: { $gt: 1 },
},
},
{
$unwind: "$docs",
},
{
$sort: {
"docs.createdAt": 1,
},
},
{
$skip: 1,
},
{
$replaceRoot: { newRoot: "$docs" },
},
]
在这里,在调用Aggregate时,我传入了下面类型中提到的"AllowDiskUse",但它仍然抛出相同的错误.
以下是我添加该选项的方式:
const options = {
allowDiskUse: true,
maxTimeMS: 10000,
}
然后使用MongoDB node 驱动程序v5.8
,使用如下所示的聚合操作:
db.collection(collectionName).aggregate(pipeline, options)
在这里,我按照错误消息的建议添加了AllowDiskUse,但它仍然不起作用.即使在MongoDB中,它也会抛出同样的错误.
那么,这里的问题是什么?
如果我能以任何其他方式实现我的目标,请发表 comments .
谢谢