MongoHQ Documentation

Documentation for using and extending the MongoHQ Platform.

MongoHQ API: Indexes

Interact with the indexes in your Mongo database’s collections.

The indexes API allows you to interact with the indexes in your MongoHQ databases. You can create, list and delete indexes.

GET /databases/:db/collections/:col/indexes

Retrieve a list of indexes for the given collection.

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

col The collection name.

Example Request:

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

POST /databases/:db/collections/:col/indexes

Create a new index under the specified collection.

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

col The collection name.

spec The index spec to be created. (ie. {name: 1})

Optional Parameters:

background Indicate that the index should be built in the background. (defaults to true)

unique If true, this index will enforce a uniqueness constraint. (defaults to false)

drop_dups 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)

min Specify the minimum longitude and latitude for a geo index. (defaults to null)

max Specify the maximum longitude and latitude for a geo index. (defaults to null)

Example Request:

curl -X POST https://api.mongohq.com/databases/vehicles/collections/rockets/indexes?_apikey=12345 \
-H "Content-Type: application/json" \
-d '{"spec" : {"name" : 1}, "background" : false, "unique" : true, "drop_dups" : true}'

DELETE /databases/:db/collections/:col/indexes/:ind

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

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name

col The collection name.

ind The index name.

Example Request:

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

DELETE /databases/:db/collections/:col/indexes

Drop ALL indexes under the specified collection.

This will delete every index in a collection. Be careful, as this cannot be undone and can cause serious performance issues for an active database.

Required Parameters:

_apikey Your MongoHQ account’s secret key.

db The database name.

col The collection name.

Example Request:

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