0

Is there a way to add allowDiscUse: true when using jongo to query MongoDB? I found out that such error - `Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in can be prevented in such a way, that your aggregate looks like

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

but as far as I see Aggregate class in Jongo only applies pipeline to itself, which you can then execute with as method.

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);

Is there any way of passing that parameter to mongo without switching from Jongo to something else?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nikita Buriak
  • 75
  • 1
  • 2
  • 11

1 Answers1

1

You can use options method :

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

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

See Jongo Aggregate test class to see a working example https://github.com/bguerout/jongo/blob/20ed6e79c0801ae1af2dc3d4fee240e201ad93dd/src/test/java/org/jongo/AggregateTest.java#L120

Benoît Guérout
  • 1,977
  • 3
  • 21
  • 30