title: Retrieve mongodb array element using java
body: <p>I have this in my db. </p>
  
  <pre><code>{
  "_id" : ObjectId("59424f41baaacf1f40815ae8"),
  "first_name" : "Yazid",
  "last_name" : "Amir",
  "gender" : "Male",
  "hobby" : ["Memanah", "Business", "Fusal", "Makan"]
  }
  </code></pre>
  
  <p>Let say that I want to retrieve the "Business" from array hobby. So my code will be like this</p>
  
  <pre><code>MongoCollection collection = db.getCollection("customers");
  BasicDBObject whereQuery = new BasicDBObject();
  whereQuery.put("first_name", "Yazid");
  
  MongoCursor&lt;Document&gt; cursor = collection.find(whereQuery).iterator();
  
  try {
  while (cursor.hasNext()) {
      Document str = cursor.next();
  
  
  
      out.println(str.get("hobby.0")); // display specific field
  }
  } finally {
  cursor.close();
  }
  </code></pre>
  
  <p>However, the result is null. </p>