database - Mongo错误QueryExceededMemoryLimitNoDiskUs

得到这个错误,当我使用这个查询时:

db2.collection('candata')
.aggregate([{$sort:{time:-1}},{$group:{_id:{batteryId:"$batteryId"},soctime:{$first:"$time"},GPSStatus:{$first:"$GPSStatus"},CANStatus:{$first:"$CANStatus"},soc: { $first : "$socpercentage" },charging_status: { $first : "$charging_status" },status: { $first : "$status" }}},{$sort:{'_id.batteryId':1}},{$lookup:{from : "swap_table",localField : "_id.batteryId",foreignField:"batteryId",as:"swap"}},{$lookup:{from : "battery_status_table",localField : "_id.batteryId",foreignField:"batteryId",as:"battery_statustb"}}])

我需要做什么改变?我不想改变查询,那么如何增加这个限制,或者我需要去一些数据归档的方法?

最佳答案

添加 allowDiskUse 并在查询结束时将其设置为 true,这样它就变成如下所示:

 db2.collection('candata')
.aggregate([{$sort:{time:-1}},{$group:{_id:{batteryId:"$batteryId"},soctime:{$first:"$time"},GPSStatus:{$first:"$GPSStatus"},CANStatus:{$first:"$CANStatus"},soc: { $first : "$socpercentage" },charging_status: { $first : "$charging_status" },status: { $first : "$status" }}},{$sort:{'_id.batteryId':1}},{$lookup:{from : "swap_table",localField : "_id.batteryId",foreignField:"batteryId",as:"swap"}},{$lookup:{from : "battery_status_table",localField : "_id.batteryId",foreignField:"batteryId",as:"battery_statustb"}}]).allowDiskUse(true)

关于database - Mongo错误QueryExceededMemoryLimitNoDiskUseAllowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66346206/

相关文章:

python - 获取包含在列表列表中的字典的值

c++ - CMake 找不到生成的 Visual Studio 15 2017 实例,但可以与 V

java - 使用 LinkedHashMap 的字符串中的第一个唯一字符

reactjs - 如何防止 Nivo 刻度轴文本(条形图)中的文本截断

c - execl参数混淆

modelica - 如何在创建实例之前在模型中重新声明包?

c - 如何打印从 C 中的 scanf 输入整数开始递减的奇数?

c++ - 如何在 constexpr if-else 链中导致静态错误?

angular - PrimeNG 报错 ConfirmationService has not b

regex - 计算 Perl 中字符串中非空白字符的数量