Description
The current MongoItemReader
uses MongoOperations.find()
method only, but MongoOperations
has also methods to issue more complex query: aggregate/aggregateStream. These 2 methods support the Mongo Aggregation Framework, as described here: https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.aggregation
For a work project, I've developed an ItemReader using MongoOperations.aggregateStream
method and I think it will be useful for the whole Spring Batch community.
I've extracted an abstract superclass from MongoItemReader
(with template, sort, collection, and type fields) to work as a base for the new MongoAggregationItemReader
class.
To complete the reader configuration, it accepts a List<AggregateOperation>
parameter. In the doPageRead method, 3 aggregation stages are added (sort, skip, limit), to accomplish the pagination needs.