【发布时间】:2020-12-28 22:39:37
【问题描述】:
所以我有以下代码:
pastlocation.aggregate([
{
'$project': {
'location': 1,
'month': {
'$month': '$timestamp'
}
}
}, {
'$match': {
'month': 11
}
},{
'$group': {
'_id': '$location.coordinates',
'count': {
'$sum': 1
}
}
}, {
'$project': {
'_id': 0,
'count': 1,
'location.coordinates': {
'$map': {
'input': '$_id',
'in': {
'$toString': '$$this'
}
}
}
}
},{$sort:{count:-1}}
]).allowDiskUse(true).exec(function(err,result) {
if(err){console.log(err)}
console.log(result)
res.json(result);
});
从我读到的所有内容来看,这是在 5.11.8 版本中使用 Mongoose 时使用 allowDiskUse 的正确方法
https://mongoosejs.com/docs/api.html#aggregate_Aggregate-allowDiskUse
但我似乎收到此错误消息。
MongoError: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting.
at MessageStream.messageHandler (/home/russellharrower/Documents/NodeApps/AdStichr-Server/node_modules/mongodb/lib/cmap/connection.js:268:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (/home/russellharrower/Documents/NodeApps/AdStichr-Server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/home/russellharrower/Documents/NodeApps/AdStichr-Server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at TLSSocket.ondata (_stream_readable.js:716:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at TLSSocket.Readable.push (_stream_readable.js:212:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23) {
operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1609147254 },
ok: 0,
code: 16819,
codeName: 'Location16819',
'$clusterTime': {
clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1609147254 },
signature: { hash: [Binary], keyId: [Long] }
}
}
我正在使用 MongoDB Atlas - 是否有需要打开的设置或遗漏了什么?
【问题讨论】:
-
它似乎正在工作,但管道阶段的问题取决于索引和数据的大小。我建议检查您正在匹配和排序的字段的索引,并尝试减少管道。如果可以的话,你可以直接使用 match 并删除第一个投影管道。
-
@MohamedKamel 感谢您的评论 - 您的意思是将日期部分放在主项目中并删除顶部的部分。问题是这个集合有超过 600,000 个文档。