List<ReportsDocument> list = new ArrayList<ReportsDocument>();
TypedAggregation aggregation = Aggregation.newAggregation(ReportsDocument.class,
match(query1),sort(Sort.Direction.ASC, "controlDocument.accountNumber")
).withOptions(new org.springframework.data.mongodb.core.aggregation.AggregationOptions.Builder().allowDiskUse(true).build());
AggregationResults<ReportsDocument> results = mongoTemplate.aggregate(aggregation,VCTCMongoCollections.REPORTING_HISTORY,ReportsDocument.class);
list = results.getMappedResults();
return list;
The full response is { "ok" : 0.0, "errmsg" : "aggregation result exceeds maximum document size (16MB)", "code" : 16389 }
at org.springframework.data.mongodb.core.MongoTemplate.handleCommandError(MongoTemplate.java:2082)
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1553)
at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1475)
at com.visa.ip.vctc.utility.OneTimeReportNAB.computeOneTimeReport(OneTimeReportNAB.java:318)
at com.visa.ip.vctc.utility.OneTimeReportNAB.run(OneTimeReportNAB.java:275)
at com.visa.ip.vctc.utility.OneTimeReportNAB.main(OneTimeReportNAB.java:179)
Caused by: com.mongodb.MongoCommandException: Command failed with error 16389: 'aggregation result exceeds maximum document size (16MB)' on server xxxxx:27017. The full response is { "ok" : 0.0, "errmsg" : "aggregation result exceeds maximum document size (16MB)", "code" : 16389 }
at com.mongodb.CommandResult.getException(CommandResult.java:80)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:94)
at org.springframework.data.mongodb.core.MongoTemplate.handleCommandError(MongoTemplate.java:2076)
... 13 morecom.mongodb.MongoCommandException: Command failed with error 16389: ‘aggregation result exceeds maximum document size (16MB)’
Hi Prasanna,
This is most likely due to the size of the aggregation query result itself exceeding the 16MB limit. The option allowDiskUse is only to enable the pipeline to write to temporary files during the stages. What you need is to use cursor in order to return the results in iterable manner.
If you’re using MongoDB driver v3.4, you can specify useCursor on the AggregateIterable object. for example:
AggregateIterable<Document> iterable = db.getCollection("collectionName").aggregate(aggPipeline).useCursor(true).allowDiskUse(true);
If you have further questions, please provide:
Regards,
Wan.
Can you please help me out with this?
Hi Prashant,
I’m not entirely clear if you’re having the same issue as the original question on this thread.
Could you please open a new discussion along with:
Could you also clarify the version of MongoDB Java driver that you’re using ?
The earliest version that is available at http://mongodb.github.io/mongo-java-driver/ is v2.13.3 for mongo-java-driver.
Regards,
Wan.
I am not really sure what are the differences between the above 2 jar files.
Hi Prashant,
The spring-data-mongodb-1.9.2.RELEASE-sources.jar is a jar for Spring Data for MongoDB. As Spring Data for MongoDB provides integration between spring-data and MongoDB, it also includes MongoDB Java Driver i.e. mongo-java-driver-2.14.0-sources.jar.
can you please tell me how to check mongo server version ?
You can use mongo shell to connect to your MongoDB instance, and execute db.serverBuildInfo().version
Alternatively, if you have access to the MongoDB server executable you can execute mongod --version on the command line. The output of these two commands will show you the server version.
im new to this so m not understanding clearly.
I would recommend to enroll in a free online course at MongoDB University to learn more about MongoDB. There’s also a course related to MongoDB Java driver.
Since you’re starting out, I would also recommend to use the current stable version of MongoDB (v3.4.10): MongoDB Download Center. Similarly with Spring Data MongoDB, you can utilise version 2.x which is compatible with MongoDB server v3.4 and MongoDB Java driver v3.4.
“aggregation result exceeds maximum document size (16MB)”
The error message is related to the result of the aggregation pipeline exceeding the 16MB BSON size limit.
There are two ways of solving this issue, the first option is to utilise cursor option for the aggregation pipeline. For Spring Data MongoDB, this option is only available since v2.0 (See DATAMONGO-1637 for more information).
Depending on your use case, the second option is to write the output of your aggregation pipeline to another collection. See aggregation operator $out.
If you have further questions related to your MongoDB deployment or MongoDB Java driver usage, please open a new thread discussion. However if you have further question related to Spring Data MongoDB please post a question on StackOverflow: spring-data-mongodb to reach wider audience with spring-data expertise.
Regards,
Wan.