首页 > 数据库技术 > 详细

mongodb 索引日常维护操作

时间:2018-10-13 21:34:57      阅读:153      评论:0      收藏:0      [点我收藏+]
创建索引:
db.t_order_detail.createIndex({"order_id":1})
复合索引:
db.t_order_detail.createIndex({"order_id":1,"detail_id":1,"batch_id":1})
在后台创建索引:
db.t_order_detail.createIndex({order_id:1},{background:1})
查看索引:
db.t_order_detail.getIndexes()
查看索引键:
db.t_order_detail.getIndexKeys()
查看集合索引总大小:
db.t_order_detail.totalIndexSize()
查看集合各索引的详细信息:
db.t_order_detail.getIndexSpecs()
删除索引:
db.t_order_detail.dropIndex("index_name")
删除所有索引
db.t_order_detail.dropIndexes()方法用于删除全部的索引
索引重建:
db.t_order_detail.reIndex({"order_id":1})

备注:
在前台创建索引期间会锁定集合,会导致其它操作无法进行数据读写,在后台创建索引,会定期释放写锁,从而保证其它操作的运行,但是后台操作会在耗时更长,尤其是在频繁进行写入的集合上。

mongodb 索引日常维护操作

原文:http://blog.51cto.com/1937519/2299640

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!