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

  IndexOptions indexOptions=new IndexOptions();
                //后台创建索引
                indexOptions.background(true);
                //唯一索引
                indexOptions.unique(true);
                //如果为true,则索引仅引用具有指定字段的文档
//                indexOptions.sparse(true);
                mongoTemplate.createCollection(collectionName).createIndex(Indexes.ascending("planId"),indexOptions);

 

posted @ 2023-08-26 16:24  余生请多指教ANT  阅读(124)  评论(0编辑  收藏  举报