我想通过Java驱动程序在MongoDB中创建基于Age
和Name
的复合索引,以下是我的语法:
coll.ensureIndex(new BasicDBObject("Age", 1),new BasicDBObject("Name", -1));
List <DBObject> list = coll.getIndexInfo();
for (DBObject o : list) {
System.out.println(o);
}
但它只创建了一个索引而不是复合索引,并给我返回以下结果:
{ "v" : 1 , "key" : { "_id" : 1} ,"ns" :"EmployeeData.EmpPersonalData", "name":"_id_"}
{ "v" : 1 , "key" : { "Age" : 1} , "ns" : "EmployeeData.EmpPersonalData" , "name" : "Age_1" , "Name" : -1}
那么如何通过Java驱动程序创建集合上的复合索引?