MongoDB新建或删除索引
生活随笔
收集整理的這篇文章主要介紹了
MongoDB新建或删除索引
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、創建索引
創建正序索引
BasicDBObject indexOptions = new BasicDBObject(); indexOptions.put("fieldName", 1); mongoOperations.getCollection(tableName).createIndex(indexOptions);創建逆序索引
BasicDBObject indexOptions = new BasicDBObject(); indexOptions.put("fieldName", -1); mongoOperations.getCollection(tableName).createIndex(indexOptions);創建唯一索引?
BasicDBObject indexOptions = new BasicDBObject(); indexOptions.put("fieldName", 1); mongoOperations.getCollection(tableName).createIndex(indexOptions, new IndexOptions().unique(true));創建復合索引?
BasicDBObject indexOptions = new BasicDBObject(); indexOptions.put("fieldName", 1); indexOptions.put("fieldName2", 1); mongoOperations.getCollection(tableName).createIndex(indexOptions);?
二、刪除索引
BasicDBObject indexOptions = new BasicDBObject(); indexOptions.put("fieldName", 1); mongoOperations.getCollection(tableName).dropIndex(indexOptions);?
三、刪除表
mongoOperations.getCollection(tableName).drop();?
總結
以上是生活随笔為你收集整理的MongoDB新建或删除索引的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 限时赠 Plus 会员年卡:魅族 20
- 下一篇: MongoDB SpringData去掉