Mongodb如果将新索引添加到已经存在的Collection中 [英] Mongodb If add new Index to already existing Collection

查看:196
本文介绍了Mongodb如果将新索引添加到已经存在的Collection中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否添加新索引,所以在添加此新索引规则时将对集合的旧文档进行索引吗?

I would like to know if I add new index the older documents of a collection will be indexed as I added this new index rule?

推荐答案

是的,所有文档(包括现有文档)都将建立索引.创建索引后,MongoDB将从头开始构建索引.

Yes, all documents including existing one will be indexed. Once you create an index, MongoDB builds index from scratch.

如果集合非常大,建议在非高峰时段创建索引,因为这将阻止对集合进行索引的所有其他操作,除非它不是后台索引操作.

It's recommended to create index during off peak hours if you have very large collection as it will block all other operations on collection being indexed, unless it's not a background index operation.

请参见 https://docs.mongodb.org/manual/reference/method/db.collection.createIndex/#behaviors

这篇关于Mongodb如果将新索引添加到已经存在的Collection中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆