Navigation

mongocli cloud-manager clusters indexes create

On this page

The clusters indexes create command creates a rolling index for a cluster in the specified Cloud Manager project. You can also create an index through the Cloud Manager UI.

Syntax

mongocli cloud-manager|cm clusters|cluster indexes|index create
   [ <index-name> ]
   [ --alternate <alternate> ]
   [ --backwards ]
   [ --caseFirst <sort-order>
   [ --caseLevel ]
   --collectionName <collection-name>
   --db <database-name>
   --key <field>:<type>
   [ --locale <ICU-locale> ]
   [ --MaxVariable <max-variable> ]
   [ --normalization ]
   [ --numericOrdering ]
   [ --projectId <project-id> ]
   --rsName <replica-set-name>
   [ --sparse ]
   [ --strength <level-of-comparison> ]
   [ --unique ]

Note

Use -h or --help to view the command-line help for this command.

Options

Option Type Description Required?
<index-name> string Name of the index to create. no
--alternate string Determines whether collation should consider whitespace and punctuations as base characters for purposes of comparison. For valid values, see Collation. no
--backwards   If set, strings with diacritics sort from the back to the front of the string. For more information, see Collation. no
--caseFirst string Determines sort order of case differences during tertiary level comparisons. For valid values, see Collation. no
--caseLevel   If set, the index uses case comparison. This field applies only if the strength level is set to 1 or 2. For more information, see Collation. no
--collectionName string Name of the collection on which to create an index. yes
--db string Name of the database that contains the collection on which to create an index. yes
--key string or array of strings

Field to be indexed and the type of index in the following format: field:type. For more information on index creation, see Indexes.

Important

If you want to create a compound index, you can:

  • Specify each field:type pair in a comma-separated list in one --key flag
  • Specify each field:type pair with a separate --key flag
yes
--locale string Locale that the ICU defines. For more information, see Collation. no
--MaxVariable string Determines up to which characters are considered ignorable when --alternate shifted. For valid values and more information, see Collation. no
--normalization   If set, collation checks if text requires normalization and performs normalization to compare text. For more information, see Collation. no
--numericOrdering   If set, collation compares numeric strings as numbers. If unset, collation compares numeric strings as strings. For more information, see Collation. no
--profile, -P string Name of the profile where the public and private keys for the project are set. If omitted, uses the default profile. To learn more about creating a profile, see Configure the MongoDB CLI. no
--projectId string Unique identifier of the project where you want to create the index. If omitted, uses the project ID in the profile or environment variable. no
--rsName string Replica set on which to build the index. yes
--sparse  

Creates an index that only references documents with the specified field. These indexes use less space but behave differently in some situations (particularly sorts). See Sparse Indexes for more information.

The following index types are sparse by default and ignore this option:

For a compound index that includes 2dsphere index key(s) along with keys of other types, only the 2dsphere index fields determine whether the index references a document.

Changed in version 3.2: Starting in MongoDB 3.2, MongoDB provides the option to create partial indexes. Partial indexes offer a superset of the functionality of sparse indexes. If you are using MongoDB 3.2 or later, partial indexes should be preferred over sparse indexes.

no
--strength integer Level of comparison to perform. For valid values, see Collation. no
--unique  

Creates a unique index so that the collection will not accept insertion or update of documents where the index key value matches an existing value in the index.

Unavailable for hashed indexes.

no

Output

The command prints the following message to the terminal:

Your index is being created

You can check the status of your index in the Cloud Manager UI, the mongo shell, or with Compass.

If the command prints an error, see Troubleshooting for recommended solutions.

Examples

Example 1

The following mongocli cm clusters indexes create command creates an index named bedrooms_1 on the listings collection of the realestate database on the replica set repl1. The command uses the default profile.

mongocli cm clusters indexes create bedrooms_1 \
--collectionName listings --db realestate --key bedrooms:1 \
--rsName repl1

The command prints the following to the terminal.

Your index is being created

Example 2

The following mongocli cm clusters indexes create command creates a compound index named property_room_bedrooms on the listings collection of the realestate database on the replica set repl1. The command uses the default profile.

mongocli cm clusters indexes create property_room_bedrooms \
--collectionName listings --db realestate --key property_type:1 \
--key room_type:1 --key bedrooms:1 --rsName repl1

The command prints the following to the terminal.

Your index is being created