【问题标题】:exceeded memory limit of 104857600 bytes on Mongodb在 Mongodb 上超过了 104857600 字节的内存限制
【发布时间】:2020-10-20 16:28:42
【问题描述】:

我要查询一个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 并查询我的数据库吗?

不接触服务器我能做什么?

【问题讨论】:

    标签: c# mongodb


    【解决方案1】:

    错误消息说明了解决方案:

    通过 allowDiskUse:true 来选择加入..

    Find方法提供可选参数FindOptions,见Find Method

    但是,根据FindOptions Class 选项allowDiskUse 不受支持。你必须测试,也许只是缺少文档。

    否则使用IMongoCollectionExtensions.Aggregate MethodAggregateOptions类支持属性AllowDiskUse

    只需用$match 包围您的状况,即"{$match: {$expr: {$ne:['$crc_n', '$crc_n_1']} } }"

    更新:我的答案中的链接是指 C# Driver 2.6。在更新的版本中,支持 allowDiskUse 属性:FindOptions Class (2.11)

    【讨论】:

      猜你喜欢
      • 2021-04-29
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 2019-06-26
      • 2018-12-22
      • 2016-07-15
      相关资源
      最近更新 更多