mongodb ensureIndex parameter

使用方法 : 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的取值范围
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值