public static void addIndex ( DBCollection collection , String field , boolean asc , boolean background ) { int dir = ( asc ) ? 1 : - 1 ; collection . createIndex ( new BasicDBObject ( field , dir ) , new BasicDBObject ( "background" , background ) ) ; }
Add an index on the given collection and field