mongodb ensureIndex parameter

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介:
使用方法 : 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数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。 &nbsp; 相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
相关文章
|
NoSQL MongoDB
MongoDB compact 命令详解
为什么需要 compact 一图胜千言 remove 与 drop 的区别 MongoDB 里删除一个集合里所有文档,有两种方式 db.collection.remove({}, {multi: true}),逐个文档从 btree 里删除,最后所有文档被删除,但文件物理空间不会被回收 db.
|
10月前
|
Oracle 关系型数据库 Shell
‘show parameter ‘ for openGauss or PostgreSQL
对于oracle DBA查看数据库实例参数可以在sqlplus中使用show prameter xxx 模糊匹配非隐藏参数或已修改隐藏参数,当然也可以查询v$ 的视图, 在openGauss或postgresql当前版本中需要匹配输入参数名,当然参数名我们不可能完全记的全名,模糊搜索需要手动创建个shell方法。
146 0
|
NoSQL MongoDB
MongoDB实现Multi tenant的方法
MongoDB实现Multi tenant的方法
228 0
MongoDB实现Multi tenant的方法
|
NoSQL 定位技术 索引
|
NoSQL 数据库
MongoDB Data Synchronization
MongoDB replica set (V3.0) synchronizes member status information through heartbeat information. Each node periodically sends heartbeat information to other members in the replica set.
2193 0
|
NoSQL 数据库
Six Reasons to Embrace MongoDB 3.x Over MongoDB 2.x
Are you still deciding if you should upgrade to the next MongoDB version? This article is lists five reasons why we think you should switch from MongoDB 2.
2434 0