确保mongodb中的索引 [英] ensureIndex in mongodb

查看:61
本文介绍了确保mongodb中的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一些问题:

  1. 如果我确保已被索引的字段上的索引,它会重新索引还是简单地说我已经被索引的话?
  2. 如果某个开发人员的机器上尚不存在该集合,mongo会启动索引吗?
  3. 我是否需要再次确保索引或调用一次?
  4. 何时索引是安全"的?必须花费一些时间...在这段时间内我的数据库被锁定了吗?

谢谢!

推荐答案

  1. ensureIndex的冗余呼叫是禁止操作.
  2. 如果ensureIndex调用中引用的集合不存在,则会创建它.
  3. 一次就够了.
  4. 除非您指定 background: true 选项,创建索引会阻止其他数据库操作.
  1. Redundant calls to ensureIndex are no-ops.
  2. If the collection referenced in the ensureIndex call doesn't exist it will be created.
  3. Once is enough.
  4. Unless you specify the background: true option, creating an index blocks other database operations.

MongoDB 3.0更新

ensureIndex在v3.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屋!

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