mongodb创建集合的时候,指定索引

发布时间 2023-08-26 16:28:50作者: 余生请多指教ANT
  IndexOptions indexOptions=new IndexOptions();
                //后台创建索引
                indexOptions.background(true);
                //唯一索引
                indexOptions.unique(true);
                //如果为true,则索引仅引用具有指定字段的文档
//                indexOptions.sparse(true);
                mongoTemplate.createCollection(collectionName).createIndex(Indexes.ascending("planId"),indexOptions);