首页 > 解决方案 > 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 图像之前,我可以使用什么临时解决方案?

标签: mongodbmongodb-querywiredtiger

解决方案


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.


推荐阅读