MongoDB is a scalable, high-performance, open source NoSQL database.
It offers Ad hoc queries, Indexing, Replication, Load balancing, File storage (GridFS), Aggregation,
MapReduce and Server-side JavaScript execution.
This requires the library mongo-2.8.0.jar to be present in the classpath.
The following example shows how to create an Index on a Collection.
try {
//Connect to mongoDB with given IP and PORT
Mongo mongo = new Mongo("localhost", 27017);
//Get the database object
DB database = mongo.getDB("mytestdb");
//Gets a collection with a given name.
DBCollection collection = database.getCollection("students");
//Create Index on provided keys
//"name", ascending order
//"age", descending order
collection.createIndex(new BasicDBObject("name", 1));
collection.createIndex(new BasicDBObject("age", -1));
//Get List of Indexes on a Collection
List<DBObject> indexes = collection.getIndexInfo();
for (DBObject o : indexes) {
System.out.println(o);
}