mongodb 索引操作

创建索引:
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.dropIndex("index_name")

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

猜你喜欢

转载自blog.51cto.com/1937519/2299640