How to set allowDiskUse:true in spring mongoTemplate
You can do like below.
MongoClient client = new MongoClient(new ServerAddress("127.0.0.1", 27017));DB test = client.getDB("test");DBCollection sample = test.getCollection("sample");List<DBObject> aggregationQuery = Arrays.<DBObject>asList( new BasicDBObject("$sort",new BasicDBObject("score",-1)), new BasicDBObject("$limit",1));System.out.println(aggregationQuery);Cursor aggregateOutput = sample.aggregate( aggregationQuery, AggregationOptions.builder() .allowDiskUse(true) .build());//rest of the code
or simply
Aggregation aggregation = newAggregation(…). withOptions(newAggregationOptions(). allowDiskUse(true).build());
You can set aggregation options like
Aggregation aggregation = newAggregation(…).withOptions(Aggregation.newAggregationOptions(). allowDiskUse(true).build());