我正在编写一个使用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.