使用方法 : db.collection.ensureIndex({keys : [1|-1|"2d"]},{options : value})

keys

Field or fields to use as index.
options

This parameter is an associative array of the form array("optionname" => <boolean>, ...). Currently supported options are:

*

"unique"

Create a unique index.
        *

"dropDups"

If a unique index is being created and duplicate values exist, drop all but one duplicate value.
        *

"background"

If you are using MongoDB version 1.3.2+, you can create indexes in the background while other operations are taking place. By default, index creation happens synchronously. If you specify TRUE with this option, index creation will be asynchronous.
        *

"safe"

Starting with driver version 1.0.4, you can specify a boolean value for checking if the index creation succeeded. The driver will throw a MongoCursorException if index creation failed.

If you are using replication and the master has changed, using "safe" will make the driver disconnect from the master, throw and exception, and attempt to find a new master on the next operation (your application must decide whether or not to retry the operation on the new master).

If you do not use "safe" with a replica set and the master changes, there will be no way for the driver to know about the change so it will continuously and silently fail to write.
        *

"name"

After driver version 1.0.4 (NOT including 1.0.4) you can specify an index name. This can be useful if you are indexing many keys and Mongo complains about the index name being too long.

使用"2d" 时,
option 还有min和max可选
指定element的取值范围

mongodb ensureIndex parameter相关推荐

  1. shell脚本实现自动化备份

    shell脚本实现自动化备份 1.备份规则: 在生产环境中有若干服务器需要定时将服务器中应用程序,以及数据库等进行备份.要求在本地服务器中保存近一周的备份,备份服务器中保存最近一月的备份文件.     ...

  2. mean shift应用_使用Google地图制作MEAN应用(第二部分)

    mean shift应用 介绍 (Introduction) Welcome back! 欢迎回来! Last time, we created an application that integra ...

  3. mongodb拆库分表脚本

    脚本功能: 1. 将指定的报告文件按照指定的字段.切库切表策略切分 2. 将切分后的文件并发导入到对应的Mongodb中 3. 生成日志文件和done标识文件 使用手册: -h    打印帮助信息,并 ...

  4. mongodb索引--1亿条记录的查询从55.7秒到毫秒级别补充版

    从头开始,验证mongodb的索引的好处.(window7环境下) 下载mongodb服务器,并解压到d盘,并使用以下命令启动 mongod --dbpath D:\mongodb\data mong ...

  5. MongoDB 索引-9

    MongoDB 索引 索引通常能够极大的提高查询的效率,如果没有索引,MongoDB在读取数据时必须扫描集合中的每个文件并选取那些符合查询条件的记录. 这种扫描全集合的查询效率是非常低的,特别在处理大 ...

  6. MongoDB非关系型数据库开发手册

    一:NoSql数据库 什么是NoSQL? NoSQL,指的是非关系型的数据库.NoSQL有时也称作Not Only SQL的缩写,是对不同于传统的关系型数据库的数据库管理系统的统称. NoSQL用于超 ...

  7. MongoDB 教程五: MongoDB固定集合和性能优化

    MongoDB 固定集合(Capped Collections) MongoDB 固定集合(Capped Collections)是性能出色且有着固定大小的集合,对于大小固定,我们可以想象其就像一个环 ...

  8. MongoDB中的索引操作

    本文来说下MongoDB中的索引操作 文章目录 概述 createIndex() 方法 语法 createIndex() 可选参数 索引操作 测试实例 本文小结 概述 索引通常能够极大的提高查询的效率 ...

  9. MongoDB的使用技巧(转)

    如果想查看当前连接在哪个数据库 下面,可以直接输入db > db Admin 想切换到test数据库下面 > use test switched to db test > db Te ...

最新文章

  1. 如何挑选靠谱的Java培训机构
  2. 正则表达式(开源框架)
  3. 浅谈line-height
  4. 6-2 函数式编程例一
  5. 我:一个女孩从软件测试工程师到主管的成长
  6. cacti气象图设置
  7. [总结]FDM 3D打印机DIY实践
  8. 智能城市dqn算法交通信号灯调度_智能交通信号灯防堵塞控制系统的制作方法
  9. 以往WiFi的最大痛点,终于被WiFi 7给解决掉了
  10. 国家何时整治程序员的高薪现象???
  11. nRF52 PWM 使用
  12. 从php角度分析预防xss和Sql注入
  13. 《羊了个羊》还在火!创始人被制成展牌,竟成母校招生“活广告”?
  14. IDEA Git 复制分支到新分支 提交到新分支
  15. 刘强东的“百亿补贴” 被指“雷”声大雨点小
  16. 李宏毅老师《机器学习》课程笔记-3卷积神经网络
  17. python3 scrapy爬取智联招聘存mongodb
  18. mt7 android6.0 回退,Mate7 M版本(Android 6.0)B553发布说明及问题反馈
  19. Qt connect有第5个参数你知道吗?
  20. 数据库计算机实验报告总结,计算机软件数据库实验报告.docx

热门文章

  1. 在centos7上使用Docker安装oracle 11g
  2. linux centos7上安装sql developer
  3. 电脑小白用Linux,linux小白说说用linux的感受
  4. bp 预测 matlab代码,bp神经网络进行交通预测的Matlab源代码.docx
  5. 使用Fiddler对iPhone手机进行数据抓包分析
  6. 阶梯英语培训学校致家长书
  7. Java学习笔记1.2.1 使用Java集成开发环境 - Eclipse
  8. 算法学习笔记:对指定金额计算最少钞票数
  9. 英语学习笔记2019-11-15
  10. 7.边缘检测:2D运算——Canny边缘原理、Canny边缘检测器、Canny-Matlab实战_2