public void createIndex ( final DBObject keys , @ Nullable final String name , final boolean unique ) { DBObject options = new BasicDBObject ( ) ; if ( name != null && name . length ( ) > 0 ) { options . put ( "name" , name ) ; } if ( unique ) { options . put ( "unique" , Boolean . TRUE ) ; } createIndex ( keys , options ) ; }
Forces creation of an index on a set of fields if one does not already exist .