Spring Data Mongodb Extracting Parts of a Sub-Documents
<p>I am using spring-data-mongodb 1.9.1. </p>

<p>My question is pretty similar to <a href="https://stackoverflow.com/questions/12730370/spring-data-mongodb-findby-method-for-nested-objects">this one</a>.</p>

<p>I have </p>

<pre><code>@Document
 public class Employee{

 private int userId;
 private List&lt;Address&gt; addresses;
 }
</code></pre>

<p>And </p>

<pre><code>@Document
public class Address{

 private int addressId;
 private String street;
 private String city:
 }
// Getters and setters
</code></pre>

<p>I have written a query and can get the value I need returned as an Employee object.</p>

<pre><code> @Query(value="{ '$and' : [ {'addresses.city' : ?0 }]} ", fields="{ 'addresses.street' : 1}")
    List&lt;Employee&gt; findStreetByEmployeeId(String fieldName);
</code></pre>

<p>My question is how can I get </p>

<p>List&lt;<strong>String</strong>> findStreetByEmployeeId(String fieldName);</p>

<p>In other words, I want to just extract the part of the result in which I am interested. 
If I have to loop through all Employee objects and extract the populated street value, it can become a very expensive operation.</p>

<p>Any thoughts on how to achieve this would be much appreciated. Thanks.</p>