1db.collection.createIndex({age:1}) //single field asc index on age field
2db.collection.createIndex({firstName:1,lastName:-1})//compound index on firstName asc and lastName desc
3db.collection.createIndex({locations:1}) //given locations is an array then a multikey index will be created
4
1> db.col1.save({'colors': ['red','blue']})
2> db.col1.ensureIndex({'colors':1})
3
4> db.col1.find({'colors': 'red'})
5{ "_id" : ObjectId("4ccc78f97cf9bdc2a2e54ee9"), "colors" : [ "red", "blue" ] }
6> db.col1.find({'colors': 'blue'})
7{ "_id" : ObjectId("4ccc78f97cf9bdc2a2e54ee9"), "colors" : [ "red", "blue" ] }
8