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 Collections

❗️

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 collection endpoint URLs begin with:

/deployments/:account/:deployment/mongodb/:database

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

EndpointDescription
GET ./collectionsList collections
GET ./collections/statsList each collections’ statistics
GET ./collections/:collectionGet one collection’s stats
POST ./collectionsCreate a collection
PUT ./collections/:collectionUpdate a collection
PATCH ./collections/:collectionModify a collection’s properties
DELETE ./collections/:collectionDestroy a collection

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

GET ./collections

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

Retrieves a list of all collection names in your database.

Request

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

Response

[
  "collection-1",
  "collection-2",
  // ...
]

GET ./collections/stats

GET /deployments/:account/:deployment/mongodb/:database/collections/stats

Retrieves statistics for all collections in your database.

Querystring Parameters

NameTypeDescription
scaleIntegerConversion factor in bytes, i.e. 1024 => db.collection.stats(1024)

Request

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

Response

[
  {
    "avgObjSize": 752,
    "count": 1,
    "indexSizes": {
      "_id_": 8176
    },
    "lastExtentSize": 45056,
    "name": "collection-1",
    "nindexes": 1,
    "ns": "database-1.collection-1",
    "numExtents": 1,
    "ok": 1,
    "paddingFactor": 1,
    "size": 752,
    "storageSize": 45056,
    "systemFlags": 0,
    "totalIndexSize": 8176,
    "userFlags": 0
  },
  // ...
]

GET ./collections/:collection

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

Retrieve statistics about a particular collection by name under the specified database.

This will return the stats from the collection. This is the same information as you would get using db.some_collection.stats().

Querystring Parameters

NameTypeDescription
scaleIntegerConversion factor in bytes, i.e. 1024 => db.collection.stats(1024)

Request

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

Response

{
  "avgObjSize": 752,
  "count": 1,
  "indexSizes": {
    "_id_": 8176
  },
  "lastExtentSize": 45056,
  "name": "collection-1",
  "nindexes": 1,
  "ns": "database-1.collection-1",
  "numExtents": 1,
  "ok": 1,
  "paddingFactor": 1,
  "size": 752,
  "storageSize": 45056,
  "systemFlags": 0,
  "totalIndexSize": 8176,
  "userFlags": 0
}

POST ./collections

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

Creates a new collection under the specified database.

Parameters

NameTypeDescription
nameStringName of the new collection, required
cappedBooleanIs this a capped collection? Defaults to false.
sizeIntegerSize in bytes for the collection, required if capped is true
maxIntegerMax number of docs for the collection, optional if capped is true

Request

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

Request (Capped Collection)

curl -i -X POST 'https://api.compose.io/deployments/your-account/deployment-1/mongodb//collections' \
-H 'Content-Type: application/json' \
-H 'Accept-Version: 2014-06' \
-H 'Authorization: Bearer [OAUTH_TOKEN]' \
-d '{"name":"collection_name","capped":true,"size":4096,"max":200}'

Response

{
  "ok": 1
}

PUT ./collections/:collection

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

Updates a particular collection by name under the specified database. This will rename a collection in your database.

Parameters

NameTypeDescription
nameStringNew name for the collection, required
dropBooleanDetermine whether source collection is dropped, defaults to false, optional

Request

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

Response

{
  "ok": 1
}

PATCH ./collections/:collection

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

Convert a particular collection to be capped under the specified database.

Parameters

NameTypeDescription
sizeIntegerSize in bytes for the collection

Request

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

Response

{
  "ok": 1
}

DELETE ./collections/:collection

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

Destroy a particular collection by name under the specified database. This will delete the collection. Be very careful, this cannot be undone!

Request

curl -i -X DELETE 'https://api.compose.io/deployments/your-account/deployment-1/mongodb//collections/collection-name' \
-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 Collections


Suggested Edits are limited on API Reference Pages

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