ensure

英[ɪn'ʃʊə(r)] US[ɛnˈʃʊr]

vt. Ensure; guarantee to obtain [avoid]; make (someone) Get; make safe

index

## English[ˈɪndeks] US[ˈɪnˌdɛks]

n.index;<number>index;instruction; Sign

vt.Index...;Index...;[Economics]Adjust by living index (wage, price, etc.)

vi.[Mechanics]Transposition

MongoDB ensureIndex() method syntax

Function: MongoDB uses the ensureIndex() method to create indexes.

Syntax: >db.COLLECTION_NAME.ensureIndex({KEY:1}) In the syntax, the Key value is the index field you want to create, and 1 specifies to create the index in ascending order. If you If you want to create indexes in descending order, specify -1.

MongoDB ensureIndex() method example

>db.col.ensureIndex({"title":1})
>
ensureIndex() 方法中你也可以设置使用多个字段创建索引(关系型数据库中称作复合索引)。

>db.col.ensureIndex({"title":1,"description":-1})
>