//设置索引名称
IndexOperations
io
=
mongoTemplate
.indexOps(
"a_"
+
location
.getIp());
Index
index
=
new
Index();
//升序倒序
index
.on(
"latitude"
,Direction.
ASC
);
index
.on(
"longitude"
,Direction.
ASC
);
io
.ensureIndex(
index
);
//
index.unique();//唯一索引
//保存数据到数据库
mongoTemplate
.save(
location
,
"a_"
+
location
.getIp());
删除索引
IndexOperations io=
mongoTemplate.indexOps(Person.
class);
io.dropIndex(
"name_1");//删除索引