title: How to create a compound index in MongoDB through Java driver?
body: <p>I want to create compound index on <code>Age</code> and <code>Name</code>  in MongoDB through Java driver and here is my syntax:</p>
  
  
  
  <pre><code>coll.ensureIndex(new BasicDBObject("Age", 1),new BasicDBObject("Name", -1));
  List &lt;DBObject&gt; list = coll.getIndexInfo();
  
    for (DBObject o : list) {
         System.out.println(o);
      }
  </code></pre>
  
  <p>but it create only  1 index not compund index and give me result this:</p>
  
  
  
  <pre><code>{ "v" : 1 , "key" : { "_id" : 1} ,"ns" :"EmployeeData.EmpPersonalData", "name":"_id_"}
  { "v" : 1 , "key" : { "Age" : 1} , "ns" : "EmployeeData.EmpPersonalData" , "name" : "Age_1" , "Name" : -1}
  </code></pre>
  
  <p>So how can compund index on collection can be created through java driver?</p>