Create indexes on JSON fields

You can create indexes on JSON data by using the DBCollection.ensureIndex(DBObject) method.

The following snippet from a Java™ program demonstrates how to create indexes on JSON fields:
 //Create an ascending integer index on 'age'
 db.collection.ensureIndex({age:[1, "$int"]}); 
 //Create ascending varchar(50) (default type) index 
 //on 'manager.name' nested object field
 db.collection.ensureIndex({"manage.name":1}}); 
The following snippet from a Java program demonstrates how to create a compound (composite) index that contains multiple fields:
 //Create compound index with two fields: name ascending 
 //with type varchar(20), and age descending as integer
 db.collection.ensureIndex({name:[1, "$string", 20], age:[-1, "$int"]}); 

For details, see the DBCollection.ensureIndex(com.ibm.nosql.json.api.DBObject) method for more details on index creation.