Mongodb和索引 [英] Mongodb and indexing
本文介绍了Mongodb和索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
两个问题:
- 如果我删除集合中的所有数据(db.mycollection.remove({}))将我之前创建的索引信息会丢失吗?
- 我应该多久(我必须有多少条目)才能重新创建索引?
推荐答案
-
调用
remove()
将删除索引数据但不是索引本身(删除集合会这样做)。因此,当您插入新文档时,它们将被添加到您在remove()
调用之前创建的索引中。
Calling
remove()
will remove the indexed data but not the indexes themselves (dropping a collection will do that). So when you insert new documents they will be added to the indexes you created prior to theremove()
call.
您无需重新创建索引。一旦您创建了索引,它将在插入/更新/删除文档时自动更新。
You don't need to recreate the index. Once you've created an index it will automatically be updated as documents are inserted / updated / removed.
这篇关于Mongodb和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文