Spring Boot and MongoTemplate: How to Use First with Group in Aggregations Sometimes you just need the first element in a group you retrieved with a MongoDB aggregation. Fortunately, that's easy to do with MongoTemplate in Spring Boot.