当前位置: 首页 > news >正文

mongodb-gridfs下载文件报Sort exceeded memory limit of 104857600 bytes异常

报错详细信息

com.mongodb.MongoQueryException: Query failed with error code 292 and error message 'Executor error during find command :: caused by :: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting.' on server 11.51.141.63:27017at com.mongodb.internal.operation.FindOperation.lambda$execute$1(FindOperation.java:670)at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$2(OperationHelper.java:564)at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589)at com.mongodb.internal.operation.OperationHelper.lambda$withSourceAndConnection$3(OperationHelper.java:563)at com.mongodb.internal.operation.OperationHelper.withSuppliedResource(OperationHelper.java:589)at com.mongodb.internal.operation.OperationHelper.withSourceAndConnection(OperationHelper.java:562)at com.mongodb.internal.operation.FindOperation.lambda$execute$2(FindOperation.java:661)at com.mongodb.internal.async.function.RetryingSyncSupplier.get(RetryingSyncSupplier.java:65)at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:692)at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:86)at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:191)at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135)at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92)at com.mongodb.client.gridfs.GridFSDownloadStreamImpl.getCursor(GridFSDownloadStreamImpl.java:240)at com.mongodb.client.gridfs.GridFSDownloadStreamImpl.getChunk(GridFSDownloadStreamImpl.java:215)at com.mongodb.client.gridfs.GridFSDownloadStreamImpl.getBuffer(GridFSDownloadStreamImpl.java:277)at com.mongodb.client.gridfs.GridFSDownloadStreamImpl.read(GridFSDownloadStreamImpl.java:101)

解决方式(给fs.chunks集合的files_id字段加索引)如

db.fs.chunks.find();db.fs.chunks.getIndexes();
# 加索引
db.fs.chunks.createIndex({files_id: 1, n: 1}, {unique: true});

加上索引后问题得以解决!


针对网上说的

1、直接修改系统限制内存大小的变量,如

use admin
db.auth("adminuser","passwd")
db.adminCommand({setParameter:1, internalQueryExecMaxBlockingSortBytes:335544320})

执行这个命令需要admin用户认证成功,当时没有创建admin用户,也不好停掉MongoDB服务去创建admin用户,所以当时没有使用过此方式。当然不是所有的版本都有此变量,可以通过如下命令查询所有可修改的变量

db.adminCommand({getParameter: '*'})

如果查到了就可以通过以上命令修改变量值,当然如MongoDB版本是5.0以上的,也可以直接修改配置文件如

setParameter:internalQueryExecMaxBlockingSortBytes: 335544320

2、开启使用磁盘(allowDiskUse)如

db.getCollection('fs.chunks').aggregate([
{$group:{_id:"$title",count:{$sum:1},title:{$addToSet:"$title"},ids:{$addToSet:"$_id"}}},{$match:{count:{$gt:1}}}],
{allowDiskUse:true})

也可以从代码层面开启使用磁盘,具体可自行搜索一下。

具体的配置含义也没有说清楚,当时试了很多次还是不行。估计是某个配置项没有配好,或者是不适用GridFs下载问题!

3、找到具体报错的集合,然后添加合适的索引。

如上面解决方式,问题得以解决。

希望能帮助到您!

http://www.lryc.cn/news/205495.html

相关文章:

  • 分享一下微信小程序里怎么实现扫码点餐链接
  • 安卓开发环境安装教程
  • 深入探究Selenium定位技巧及最佳实践
  • 如何正确安装psycopg2,No module named ‘psycopg2._psycopg‘解决
  • go WriteFile文件追加写入(适合小文件)
  • history 模式上线需要注意什么事项?
  • VMware虚拟机安装Ubuntu22.04教程(2023最新最详细)
  • yakit使用爆破编码明文_dnslog使用
  • 3分钟教你用Python+Appium实现自动化测试
  • qt的一些自绘控件
  • 类图表示法
  • 大模型训练框架
  • 好用的Visio绘图文件工具 VSD Viewer最新 for mac
  • 三代自动驾驶系统及主流科技公司自动驾驶技术方案简介
  • mac安装nodejs,跑vue程序
  • VC++程序崩溃时,使用Visual Studio静态分析dump文件
  • 【哈希数组】【字符串 转化为 字符数组】Leetcode 383 赎金信
  • 【C++】c++引用和小细节
  • nginx负载均衡(动静分离)
  • vue自定义全局指令v-emoji限制input输入表情和特殊字符
  • Excel 5s内导入20w条简单数据(ExecutorType.BATCH)Mybatis批处理的应用
  • 【期刊】IEEE系列指定期刊模版下载(LaTeX或者Word)全网最细教程
  • 损失函数和评估函数
  • 第四章 文件管理 四、文件的物理结构(文件分配方式)
  • 解析外贸开发信的结构?营销邮件书写技巧?
  • Linux的命令基本格式
  • 数据库Redis(二):基本数据类型
  • mysql第四次作业
  • kubesphere 一键部署K8Sv1.21.5版本
  • 设计模式(12)状态模式