gpt4 book ai didi

java - Spring 中 'Sort exceeded memory limit' MongoDb 的问题

转载 作者:可可西里 更新时间:2023-11-01 10:36:23 26 4
gpt4 key购买 nike

我正在编写一个使用 MongoRepository 实现查询的方法,我在 Java/Spring 项目中使用聚合,但在我测试时它给出了超出的内存限制。

我试过

newAggregationOptions().cursorBatchSize(pageable.getPageSize()).allowDiskUse(true).build()

但没用

我的方法:

...
var matchCriteria = match(criteria);

var unwindVariations = unwind("variations", false);


var sort = sort(Sort.Direction.ASC, "variations.plataformStatus.status");

var countResult = count().as("totalElements");
var aggregationOptions = Aggregation.newAggregationOptions().cursorBatchSize(pageable.getPageSize()).allowDiskUse(true).build();

var countAggregation = newAggregation(
matchCriteria,
unwindVariations,
sort,
countResult)
.withOptions(aggregationOptions);

var totalElements = mongoTemplate.aggregate(countAggregation, "PRODUCT", Map.class).getMappedResults();


错误信息:

com.mongodb.MongoCommandException: Command failed with error 16819 (Location16819): 'Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.' on server cluster0-shard-00-01-du380.mongodb.net:27017.

最佳答案

您应该启用allowDiskUse 选项。

默认情况下,排序操作有 100MB 的限制(在内存中),在您的操作中启用该选项将允许使用更大的大小。

来自 MongoDB's sort documentation :

The $sort stage has a limit of 100 megabytes of RAM. By default, if the stage exceeds this limit, $sort will produce an error. To allow for the handling of large datasets, set the allowDiskUse option to true to enable $sort operations to write to temporary files.

关于java - Spring 中 'Sort exceeded memory limit' MongoDb 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56477485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com