mongodb建立索引&查看索引&删除索引
2019-03-01 本文已影响1人
布口袋_天晴了
从Robo 3T可视化界面中,去创建mongodb数据表的索引。
1.数据表结构:{_id:value, doc_city:value, doc_province:value, content, judgementId}
![](https://img.haomeiwen.com/i6102062/947175d3ebd71011.png)
2.content字段展开:
![](https://img.haomeiwen.com/i6102062/2fb3f2a5845018d0.png)
3.对content字段里的title/caseType/judgementType建立索引
db.getCollection('chongqing').createIndex({"content.title":1, "content.judgementType":1, "content.caseType":1})
![](https://img.haomeiwen.com/i6102062/3e9fb200bbcd21fa.png)
4.让创建索引的过程在后台运行
db.getCollection('chongqing').createIndex({"content.title":1, "content.judgementType":1, "content.caseType":1},{background:true})
![](https://img.haomeiwen.com/i6102062/a7d0f345611aff68.png)
5.查询集合索引
db.getCollection('chongqing').getIndexes()
![](https://img.haomeiwen.com/i6102062/ffc408906b7fa8b8.png)
6.查看索引集合大小
db.getCollection('chongqing').totalIndexSize()
![](https://img.haomeiwen.com/i6102062/ff8adefbdd71e6b4.png)
7.删除集合所有索引
db.getCollection('chongqing').dropIndexes()
8.删除集合指定索引
db.getCollection('chongqing').dropIndex('索引名')