确保mongodb中的索引 [英] ensureIndex in mongodb
本文介绍了确保mongodb中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一些问题:
- 如果我确保已被索引的字段上的索引,它会重新索引还是简单地说我已经被索引的话?
- 如果某个开发人员的机器上尚不存在该集合,mongo会启动索引吗?
- 我是否需要再次确保索引或调用一次?
- 何时索引是安全"的?必须花费一些时间...在这段时间内我的数据库被锁定了吗?
谢谢!
推荐答案
- 对
ensureIndex
的冗余呼叫是禁止操作. - 如果
ensureIndex
调用中引用的集合不存在,则会创建它. - 一次就够了.
- 除非您指定
background: true
选项,创建索引会阻止其他数据库操作.
- Redundant calls to
ensureIndex
are no-ops. - If the collection referenced in the
ensureIndex
call doesn't exist it will be created. - Once is enough.
- Unless you specify the
background: true
option, creating an index blocks other database operations.
MongoDB 3.0更新
ensureIndex
was deprecated in v3.0 and is now an alias for createIndex
, so createIndex
should be used instead. The behavior remains the same.
这篇关于确保mongodb中的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文