Spring Data MongoDB has helpful builder classes for aggregation stages, like Aggregation.match() or Aggregation.sort(). Objects returned by those methods implement the AggregationOperation interface, which allows them to be used Aggregation.newAggregation() to create a new pipeline, which is in turn passed to mongoTemplate.aggregate().
The problem is not all Mongo aggregation stages have builder methods, e.g. $lookup with a correlated subquery. It appears in those cases I have to manually create a Document with JSON describing the stage. But I can't find a way to use an AggregationOperation and a Document based stage together. Is there a way to wrap a Document into an AggregationOperation, or similar?