源代码如下:
//这个是判断集合是不是还没有创建 long count = mongoTemplates.count(new Query(), "名单集"); if(count <= 0 ){ System.out.println(count); //开始创建索引 Index index = new Index(); index.on("name_value", Sort.Direction.DESC); index.on("name_list_set_type", Sort.Direction.DESC); index.on("name_list_set_name", Sort.Direction.DESC); index.on("name_flag", Sort.Direction.DESC); //给那个集合创建索引 mongoTemplates.indexOps("名单集").ensureIndex(index); }