title: How do I retrieve a subset of fields using Spring's MongoTemplate and Query classes?
body: <p>I want to be able to execute the following console command to return all rows with only a subset of fields populated but using Spring's <a href="https://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoTemplate.html" rel="nofollow noreferrer"><code>MongoTemplate</code></a> class:</p>
  <p><strong>Console Command</strong></p>
  <pre class="lang-javascript prettyprint-override"><code>db.person.find(null,{name:1})
  </code></pre>
  <p><strong>MongoTemplate</strong></p>
  <pre class="lang-java prettyprint-override"><code>mongoTemplate.find(new Query(...), Person.class)
  </code></pre>
  <p>Info on projection (subset) queries can be found <a href="https://docs.mongodb.com/manual/tutorial/project-fields-from-query-results/" rel="nofollow noreferrer">in the MongoDB manual</a>.</p>