1
当前我在春季使用mongoDB作为mongoTemplate。如何在弹簧中设置allowDiskUse:true mongoTemplate
public List<BasicDBObject> getMoviesByName() {
Aggregation aggregation = newAggregation(unwind("movies"),
match(where("movies.language").is("english")),
sort(Sort.Direction.DESC, "createDate"),
group(fields().and("_id", "$_id").and("category", "$category")).push("$movies").as("movies"),
project(fields().and("category", "$category").and("movies", "$movies")).andExclude("_id"));
AggregationResults<BasicDBObject> groupResults = mongoTemplate.aggregate(
aggregation, "movieCollection", BasicDBObject.class);
return groupResults.getMappedResults();
}
我得到异常
com.mongodb.CommandFailureException: { "serverUsed" : "XXX.XXX.XX.XX:27017" , "errmsg" : "exception: Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in." , "code" : 16819 , "ok" : 0.0}
我研究过一些帖子allowDiskUse:真正的解决方案,我已经尝试设置为true,但没有结果。请告诉我如何为上面的代码
设置
聚合选项你试过'AggregationResults groupResults = mongoTemplate.aggregate( 聚集, “movieCollection”,BasicDBObject .class).withOptions(newAggregationOptions()。allowDiskUse(true).build());'? –
chridam
我已经尝试了上面的代码,但没有结果 –