gpt4 book ai didi

java - 使用 Jongo 时允许光盘使用

转载 作者:行者123 更新时间:2023-12-01 10:03:20 25 4
gpt4 key购买 nike

使用jongo查询MongoDB时有没有办法添加allowDiscUse: true?我发现这样的错误 - `排序超出了 104857600 字节的内存限制,但没有选择外部排序。正在中止操作。通过allowDiskUse:true 来选择加入可以通过这样的方式来阻止,您的聚合看起来像

aggregate([{$sort:...},{$$skip:...}...],{allowDiscUse: true})

但据我所知,Jongo 中的Aggregate 类仅将管道应用于自身,然后您可以使用 as 方法执行该管道。

MongoCollection catalogCollection = mongoHolder.getCatalogJongo(param.id, false);

Aggregate aggregation = catalogCollection.aggregate("{$match: #}", query.build());
aggregation.and("{$skip: #}", param.offset);
aggregation.and("{$limit: #}", param.limit);
List<BasicDBObject> result = aggregation.as(BasicDBObject.class);

有什么方法可以将该参数传递给 mongo 而无需从 Jongo 切换到其他东西吗?

最佳答案

您可以使用选项方法:

AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).build());

List<BasicDBObject> result = collection.aggregate("...").options(options).as(BasicDBObject.class);

请参阅 Jongo Aggregate 测试类以查看工作示例 https://github.com/bguerout/jongo/blob/20ed6e79c0801ae1af2dc3d4fee240e201ad93dd/src/test/java/org/jongo/AggregateTest.java#L120

关于java - 使用 Jongo 时允许光盘使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36642619/

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