错误截图

在这里插入图片描述

官方文档解释

在这里插入图片描述

原因 :

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;
}
Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐