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.
Endpoint | Description |
---|---|
GET ./indexes | List indexes |
POST ./indexes | Create an index |
DELETE ./indexes/:index | Drop an index |
Common Parameters
Param | Description |
---|---|
:account | An account slug |
:deployment | A deployment id or name |
:database | The name of a database on :deployment |
:collection | The name of a collection in :database |
:index | The 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
Name | Type | Description |
---|---|---|
fields | Array | Fields to index, + is ascending, - is descending |
unique | Boolean | If true, this index will enforce a uniqueness constraint, defaults to false |
sparse | Boolean | If 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_dups | Boolean | If 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 |
expireAfterSeconds | Integer | Time 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 |
background | Boolean | Indicate 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