Navigation

Create a Rolling Index

The Atlas API authenticates using HTTP Digest Authentication. Provide a programmatic API public key and corresponding private key as the username and password when constructing the HTTP request.

To learn how to configure API access for an Atlas project, see Configure Atlas API Access.

https://cloud.mongodb.com/api/atlas/v1.0

POST /groups/{GROUP-ID}/clusters/{CLUSTER-NAME}/index

You must have one of the following roles to successfully call this resource:

Path ElementRequired/OptionalDescription
GROUP-IDRequired.Unique identifier of the project which holds the cluster on which to create an index.
CLUSTER-NAMERequired.The name of the cluster on which to create an index.

This endpoint has no request query parameters.

NameTypeDescriptionRequired
dbstringThe name of the database that holds the collection on which to create an index.Required
collectionstringThe name of the collection on which to create an index.Required
keysarray of objects

An array containing one or more objects in which the key is the field to be indexed and the value is the type of the index. For more information on index creation syntax, see the createIndex() shell method.

Important With Circle IconCreated with Sketch.Important

If you want to create a multikey index, you must list each field in its own object within the keys object array. JSON does not guarantee item order, so if you list multiple fields in the same object, the index may not build correctly.

Required
optionsobjectA document that contains a set of options that controls the creation of the index. See Index Options for more information.Optional
collationobjectA document that contains a set of options to control index collation. See Collation Options for more information.Optional

This endpoint returns an empty document.

curl -u "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--request POST "https://cloud.mongodb.com/api/atlas/v1.0/groups/{GROUP-ID}/clusters/{CLUSTER-NAME}/index" \
--data '{
"db": "test",
"collection": "myCollection",
"keys": [{ "myField": 1 }],
"collation": { "locale": "us", "strength": 2 }
}'
{}
Give Feedback