title: How to use FindIterable<Document> to get the specific field from mongodb using java
body: <p>Here,I'm trying to retrieve the status field if the name matches.How to use FindIterable instead of DBCursor.Can anyone please help me out ...</p>
  
  <p>My code:</p>
  
  <pre><code>  public String getStatus(String name) throws Exception{
               MongoClient mongo = new MongoClient("localhost",27017);
               MongoDatabase db = mongo.getDatabase("counter");
               MongoCollection&lt;Document&gt; col = db.getCollection("status");
  
              Document query = new Document();
              query.put("name", name);
              query.put("status", 1);
  
              Document fields = new Document();
              fields.put("status", 1);
              fields.put("_id", 0);
  
               DBCursor cursor = collection.find(query,fields);
  
               while(cursor.hasNext()){
                      System.out.println(cursor.next());
                  }
  
          return "SUCCESS";
          }
  </code></pre>