MongoHQ Documentation

Documentation for using and extending the MongoHQ Platform.

MongoHQ API: Collections

Interact with collections in your MongoDB database.

The collections API allows you to interact with the collections in your MongoHQ databases. You can create, get info, rename & delete collections. Below is a detailed list of the current options.

GET /databases/:db/collections

This retrieves a list of all collections in your database.

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The name of the MongoHQ database you want to use.

Example Request:

curl -X GET http://api.mongohq.com/databases/vehicles/collections?_apikey=12345

POST /databases/:db/collections

Create a new collection under the specified database.

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

name The collection name.

Example Request:

curl -X POST http://api.mongohq.com/databases/vehicles/collections?_apikey=12345 \
-H "Content-Type: application/json" \
-d '{"name":"my_new_collection"}'

GET /databases/:db/collections/:col

Retrieve 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()

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

col The collection name.

Example Request:

curl -X GET http://api.mongohq.com/databases/vehicles/collections/rockets?_apikey=12345

PUT /databases/:db/collections/:col

Update a particular collection by name under the specified database. TiYou can rename a collection in your database.

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

col The original collection name.

name The new collection name.

Example Request:

curl -X PUT http://api.mongohq.com/databases/vehicles/collections/rockets?_apikey=12345 \
-H "Content-Type: application/json" \
-d '{"name":"my_collection_renamed"}'

DELETE /databases/:db/collections/:col

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

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

col The original collection name.

Example Request:

curl -X DELETE http://api.mongohq.com/databases/vehicles/collections/rockets?_apikey=12345