title: Spring Boot Data and MongoDB - Filter Subdocument Array Query
body: <p>I am attempting to use Spring to Query a Mongo repository and filter an array subdocument.  I have referenced <a href="https://stackoverflow.com/questions/15117030/how-to-filter-array-in-subdocument-with-mongodb/">how to filter array in subdocument with mongodb</a>, but was wondering if there was a more appropriate or java structured method to do so using Spring.</p>
  
  <p>I am currently using the shorthand repository interface notation, but I am getting back the complete document with the array not filtered.</p>
  
  <p><strong>PersonRepository.java</strong></p>
  
  <pre><code>@Repository
  public interface PersonRepository extends MongoRepository &lt;Person, String&gt; {
      List&lt;Person&gt; findByAddressZipCode(@Param("zip") int zip);
  }
  </code></pre>
  
  <p><strong>Person.java</strong></p>
  
  <pre><code>@Document
  public class Person {
      @Id
      private String id;
  
      private String firstName;
      private String lastName;
      private List&lt;Address&gt; address;
  }
  </code></pre>
  
  <p><strong>Address.java</strong></p>
  
  <pre><code>public class Address {
      private int zip;
  }
  </code></pre>
  
  <p><strong>Sample Input</strong></p>
  
  <pre><code>{
   "firstName":"George",
   "lastName":"Washington",
   "address":[{
       "zip":"12345"
    },{
       "zip":"98765"
    },{
       "zip":"12345"
    }]
  }
  </code></pre>
  
  <p><strong>Expected Output</strong></p>
  
  <pre><code>{
   "firstName":"George",
   "lastName":"Washington",
   "address":[{
       "zip":"12345"
    },{
       "zip":"12345"
    }]
  }
  </code></pre>
  
  <p><strong>Actual Output</strong></p>
  
  <pre><code>{
   "firstName":"George",
   "lastName":"Washington",
   "address":[{
       "zip":"12345"
    },{
       "zip":"98765"
    },{
       "zip":"12345"
    }]
  }
  </code></pre>