title: How to query only the specific fields in MongoDB with Java?
body: <p>I'm using MongoDB 3.2 and MongoDB Java Driver 3.2. In order to query document I use the following code:</p>
  
  <pre><code>Document query = new Document("fetchStatus", new Document("$lte", fetchStatusParam));
  ArrayList&lt;Document&gt; unfetchedEvents = dbC_Events.find(query).into(new ArrayList&lt;Document&gt;());
  </code></pre>
  
  <p>This query works but the problem is that in this case all fields of the document are retrieved (analog of <code>select *</code> in SQL). In order to optimize query performance, I want to specify fields I really need and fetch only them.</p>
  
  <p>I found couple of examples, such as:</p>
  
  <pre><code>BasicDBObject query = new BasicDBObject();
  BasicDBObject fields = new BasicDBObject("Name", 1);
  coll.find(query, fields);
  </code></pre>
  
  <p>but all of them are designed for outdated version of MongoDB Java Driver, e.g. 2.4, while I'm using 3.2.</p>
  
  <p><strong>My question:</strong><br>
  How can I query only specific fields of document in MongoDB Java Driver 3.2?</p>