mongodb - MongoDB 在读取操作时关闭连接
问题描述
我在 Ubuntu Server 16.04 下的 WiredTiger 上运行 MongoDB 4.0 来存储复杂的文档。其中一个集合存在问题:文档中有许多以 base64 字符串形式写入的图像。我知道这是一种不好的做法,但我需要一些时间来解决它。
因此,某些find
操作会失败,但只有那些具有非空过滤器或skip
. 例如在超时后关闭连接db.collection('collection').find({})
时运行正常。db.collection('collection').find({category: 1})
应该返回多少个文档并不重要:如果有过滤器,每次都会弹出错误(即使它应该返回 0 个文档),而空查询总是执行良好,直到skip
太大。
UPD:某些skip
值使查询失败。db.collection('collection').find({}).skip(5000).limit(1)
运行良好,db.collection('collection').find({}).skip(9000).limit(1)
花费大量时间但也执行,但db.collection('collection').find({}).skip(10000).limit(1)
每次都失败。看起来有某种缓冲区,数据库在其中存储与查询相关的数据,并且在 10000 个文档上它耗尽了资源。该集合本身有大约 10500 个文档。此外,按_id
运行搜索即可。不幸的是,我没有机会创建新索引,因为操作失败就像read
.
在从集合中删除 base64 图像之前,我可以使用什么临时解决方案?
解决方案
This happens because such a problematic data scheme causes huge RAM usage. The more entities there are in the collection, the more RAM is needed not only to perform well but even to run find
.
Increasing MongoDB default RAM usage with storage.wiredTiger.engineConfig.cacheSizeGB
config option allowed all the operations to run fine.
推荐阅读
- c# - 将多个引用表连接到主表的 Lambda 语法
- math - 缩放后如何计算网格内给定点的坐标
- python - 在python中计算给定数字的前两个因子(除了1)的程序
- visual-studio-code - 使用 Intelephense 的 VS 代码不读取对象的可用方法
- python - 如何转换
python中元组中的数据? - flutter - 如何在flutter中使用文件路径获取文件元数据
- angular - Docker + Angular:docker 参数不适用于 ng build
- r - rvest web-scraped info 格式化列
- spring - 由 Spring 启动但不在 Postgresql Sql 编辑器中时遇到错误
- eclipse - Eclipse RCP 捕获 System out println