Compose Database-as-a-Service Help and Documentation

Everything you need to know about Compose, Hosted or Enterprise, is here in our help system. Whether you run one database for your businesses' sole application or six different databases to support an entire corporation, we've got the information you need.

MongoDB Indexes

❗️

This is the older REST API and is now deprecated.

Go to the dedicated apidocs.compose.com for details of the current API which works with all Compose databases with the exception of the MongoDB Classic deployments.

📘

Base URL

All MongoDB index endpoint URLs begin with:

/deployments/:account/:deployment/mongodb/:database/collections/:collection

To improve readability, we’ve substituted a . for this string in the descriptions below.

EndpointDescription
GET ./indexesList indexes
POST ./indexesCreate an index
DELETE ./indexes/:indexDrop an index

Common Parameters

ParamDescription
:accountAn account slug
:deploymentA deployment id or name
:databaseThe name of a database on :deployment
:collectionThe name of a collection in :database
:indexThe name of an index in :collection

GET ./indexes

GET /deployments/:account/:deployment/mongodb/:database/collections/:collection/indexes

Retrieve a list of indexes for the given collection.

Request

curl -i -X GET 'https://api.compose.io/deployments/your-account/deployment-1/mongodb/database-1/collections/collection-name/indexes' \
-H 'Content-Type: application/json' \
-H 'Accept-Version: 2014-06' \
-H 'Authorization: Bearer [OAUTH_TOKEN]'

Response

[
  {
    key: {
      _id: 1
    },
    name: "_id_",
    ns: "database-1.collection-1",
    v: 1
  },
  // ...
]

POST ./indexes

POST /deployments/:account/:deployment/mongodb/:database/collections/:collection/indexes

Create a new index under the specified collection.

Parameters

NameTypeDescription
fieldsArrayFields to index, + is ascending, - is descending
uniqueBooleanIf true, this index will enforce a uniqueness constraint, defaults to false
sparseBooleanIf true, index will only contain entries for documents that have the indexed field, even if the index field contains a null value defaults to false
drop_dupsBooleanIf creating a unique index on a collection with pre-existing records, this option will keep the first document the database indexes and drop all subsequent with duplicate values, defaults to false
expireAfterSecondsIntegerTime in seconds for the specified field to remain in collection, if used, you may only specify 1 field and it must be of type ISODate
backgroundBooleanIndicate that the index should be built in the background, defaults to true

Request

curl -i -X POST 'https://api.compose.io/deployments/your-account/deployment-1/mongodb/database-1/collections/collection-name/indexes' \
-H 'Content-Type: application/json' \
-H 'Accept-Version: 2014-06' \
-H 'Authorization: Bearer [OAUTH_TOKEN]' \
-d '{"fields":["+name","-last"]}'

Response

{
  "ok": 1
}

DELETE ./indexes/:index

DELETE /deployments/:account/:deployment/mongodb/:database/collections/:collection/indexes/:index

Drop single index by index-name under the specified collection.

Request

curl -i -X DELETE 'https://api.compose.io/deployments/your-account/deployment-1/mongodb/database-1/collections/collection-name/indexes/index_1' \
-H 'Content-Type: application/json' \
-H 'Accept-Version: 2014-06' \
-H 'Authorization: Bearer [OAUTH_TOKEN]'

Response

{
  "ok": 1
}

Still Need Help?

If this article didn't solve things, summon a human and get some help!

Updated about a year ago

MongoDB Indexes


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.