c# - 在 Mongodb 上超过了 104857600 字节的内存限制
问题描述
我必须查询一个 mongodb 数据库
我正在这样做:
var filter = Builders<BsonDocument>.Filter.Eq("origine", sOrigin)
& BsonDocument.Parse("{$expr: {$ne:['$crc_n', '$crc_n_1']} }");
var sort = Builders<BsonDocument>.Sort.Ascending("update_date");
List<BsonDocument> docs = collection.Find(filter).Sort(sort)
.Limit(5000)
.ToList();
但我有这个消息:
Command find failed: Executor error during find command :: caused by :: Sort
exceeded memory limit of 104857600 bytes, but did not opt in to external sorting.
Aborting operation. Pass allowDiskUse:true to opt in.."}
我不想更改限制或自定义服务器。我想通过代码进行管理。
我必须使用限制较小的线程吗?
我必须使用 ConcurrentBag 并查询我的数据库吗?
不接触服务器我能做什么?
解决方案
错误消息说明了解决方案:
通过 allowDiskUse:true 选择加入..
该Find
方法提供可选参数FindOptions
,请参见查找方法。
但是,不支持根据FindOptions 类选项。allowDiskUse
您必须进行测试,也许只是缺少文档。
否则使用IMongoCollectionExtensions.Aggregate 方法,AggregateOptions
该类支持属性AllowDiskUse
只需将您的条件包围$match
,即"{$match: {$expr: {$ne:['$crc_n', '$crc_n_1']} } }"
更新: 我的答案中的链接是指 C# Driver 2.6。在更新的版本allowDiskUse
中支持属性:FindOptions Class (2.11)
推荐阅读
- r - 将2个向量组合成R中的矩阵时如何保留/分配行名和列名
- python - 如何获取Dataframe中最大值和最小值的上一个和下一个值
- php - 如何在php网页上显示两个表格数据
- c - inet_ntop() 未在此范围内清除
- python - Scikit-Learn + Scipy.optimize 高斯过程回归中的外部优化器
- xml - 从结构生成特定格式的 XML
- javascript - 什么时候可以考虑断开 RTCPeerConnection?
- azure - 如何为 MS Azure Speech to Text 服务启用字级置信度
- javascript - Jest 测试在本地通过,但在 azure devops 中失败
- java - Maven:如何将现有的 Maven 项目拆分为不同的项目?