title: Map aggregate query result to correct attributes of POJO
body: <p>I have a collection named Location which has couple of attributes of which I want to fetch only country code and country name.</p>
  <p>When I'm using below aggregation query in Spring Data, all the attributes are getting mapped to the _id attribute of Location.java and not to individual countryCode and countryName attribute of the List. Please help me resolve the same.</p>
  <pre><code>@Repository
  public class AggregateQueryRepository {
      
  @Autowired
  ReactiveMongoTemplate reactiveMongoTemplate;
   
  public Flux&lt;Location&gt; getAllCountryCodeAndCountry() {
          Aggregation aggregation = newAggregation(group(&quot;countryCode&quot;, &quot;countryName&quot;)
          );
          return reactiveMongoTemplate.aggregate(aggregation, &quot;location&quot;, Location.class);
      }
  }
  </code></pre>
  <p>Currently each object of the result looks like below:</p>
  <pre><code>{ &quot;_id&quot;: &quot;{\&quot;countryCode\&quot;: \&quot;IN\&quot;, \&quot;countryName\&quot;: \&quot;India\&quot;}&quot; }
  </code></pre>
  <p>I want to map it to something like below:</p>
  <pre><code>{
  { &quot;_id&quot;: null,
  &quot;countryCode&quot;: &quot;ÏN&quot;
  &quot;countryName&quot;: &quot;India&quot;
  },
  ....
  .....
  }
  </code></pre>