mongodb分页排序问题 Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting
·
错误截图

官方文档解释

原因 :
mongodb排序超出了 104857600 字节的内存限制( 底层聚合管道受限于 100 兆字节的内存限制 ) ;
从 MongoDB 4.4 开始,您可以在视图上发出 find命令 allowDiskUse: true以允许 MongoDB 使用临时文件来阻止排序和分组操作;
在 MongoDB 4.4 之前,只有aggregate命令接受该 allowDiskUse
java使用
@Autowired
private MongoTemplate mongoTemplate;
/**
* 指定条件查找
* @param query /
* @param collName /
* @return /
*/
public List<Document> findAll(BasicDBObject query, String collName){
MongoCollection<Document> coll = mongoTemplate.getCollection(collName);
List<Document> result = new ArrayList<>();
FindIterable<Document> findIterable = coll.find(query).allowDiskUse(true);
for (Document document : findIterable) {
result.add(document);
}
return result;
}
更多推荐
所有评论(0)