'Java MongoTemplate: aggregation using String criteria

Context

I need to rewrite some code previoulsy with Jongo but using Springframework MongoDb. Previous code was:

eventsCollection
  .aggregate("{$match:" + query + "}")
  .and("{$group: {_id: '$domain', domain: {$first: '$domain'}, codes: {$push: '$code'}}}")
  .and("{$project : { _id: 0, domain: 1 , codes: 1 } }")
  .as(DomainCodes.class);

where eventsCollection is Jongo MongoCollection, and query is a String containing with criteria.

Problem

New code must probably look like :

Aggregation myAggregation = Aggregation.newAggregation(
  Aggregation.match(/* something here */),
  Aggregation.group("domain").first("domain").as("domain").push("code").as("codes")
);
mongoTemplate.aggregate(myAggregation, "collectionName", DomainCodes.class);

but I don't find a way to create match criteria using String (similare as BasicQuery that can take a query as String for argument)

Question

In order to change as little code as possible, is there anyway to use query String as in Jongo ?

Thank you,



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source