码迷,mamicode.com
首页 > 数据库 > 详细

mongodb 索引日常维护操作

时间:2018-10-13 21:42:16      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:mongod   dex   back   index   order   rop   集合   ecs   name   

创建索引:
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 索引日常维护操作

标签:mongod   dex   back   index   order   rop   集合   ecs   name   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!