I have the bellow query to MongoDB:
public void query11(String product, int limit) {
printBlock = new Consumer<UserBson>() {
@Override
public void accept(final UserBson user) {
System.out.println("Hola");
if (cantResults < limit) {
System.out.println("#=[" + (cantResults + 1) + "]\t_id:" + user.getId() );
cantResults++;
}
}
};
connect.getCollection().aggregate(
Arrays.asList(
Aggregates.match(Filters.exists("scores")),
Aggregates.unwind("$scores"),
Aggregates.project(Projections.include("name", "secondName", "lastName", "secondLastName", "sales.products.name")),
Aggregates.sort(Sorts.ascending("_id"))
)
).forEach(printBlock);
totalTime = (System.currentTimeMillis() - startTimeT);
}
But Mongo is responding with:
Preformatted textException in thread “main” com.mongodb.MongoCommandException:
Command failed with error 16819 (Location16819): ‘Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.’ on server 127.0.0.1:27017. The full response is {“ok”: 0.0, “errmsg”: “Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting. Aborting operation. Pass allowDiskUse:true to opt in.”, “code”: 16819, “codeName”: “Location16819”}