atlas clusters indexes create
On this page
Create a rolling index for the specified cluster for your project.
To use this command, you must authenticate with a user account or an API key with the Project Data Access Admin role.
Syntax
atlas clusters indexes create [indexName] [options]
Arguments
Name | Type | Required | Description |
---|---|---|---|
indexName | string | false | Name of the index. |
Options
Name | Type | Required | Description |
---|---|---|---|
--clusterName | string | true | Name of the cluster. To learn more, see https://dochub.mongodb.org/core/create-cluster-api. |
--collection | string | false | Name of the collection. Mutually exclusive with --file. |
--db | string | false | Name of the database. Mutually exclusive with --file. |
-f, --file | string | false | Path to an optional JSON configuration file that defines index settings. Mutually exclusive with --db, --collection, --key. |
-h, --help | false | help for create | |
--key | strings | false | Field to be indexed and the type of index in the following format: field:type. Mutually exclusive with --file. |
--projectId | string | false | Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable. |
--sparse | false | Flag that creates a sparse index. To learn more, see https://dochub.mongodb.org/core/index-sparse-manual. |
Inherited Options
Name | Type | Required | Description |
---|---|---|---|
-P, --profile | string | false | Name of the profile to use from your configuration file. To learn about profiles for the Atlas CLI, see https://dochub.mongodb.org/core/atlas-cli-save-connection-settings. |
Examples
# Create an index named bedrooms_1 on the listings collection of the realestate database: atlas clusters indexes create bedrooms_1 --clusterName Cluster0 --collection listings --db realestate --key bedrooms:1
# Create a compound index named property_room_bedrooms on the listings collection of the realestate database: atlas clusters indexes create property_room_bedrooms --clusterName Cluster0 --collection listings --db realestate --key property_type:1 --key room_type:1 --key bedrooms:1
# Create an index named my_index from a JSON configuration file named myfile.json: atlas clusters indexes create my_index --clusterName Cluster0 --file file.json