【发布时间】:2012-07-14 09:03:40
【问题描述】:
我想通过 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);
}
但它只创建 1 个索引而不是复合索引并给我结果:
{ "v" : 1 , "key" : { "_id" : 1} ,"ns" :"EmployeeData.EmpPersonalData", "name":"_id_"}
{ "v" : 1 , "key" : { "Age" : 1} , "ns" : "EmployeeData.EmpPersonalData" , "name" : "Age_1" , "Name" : -1}
那么如何通过java驱动创建comund index on collection呢?
【问题讨论】:
标签: java mongodb indexing mongodb-java