driver-legacy/src/main/com/mongodb/DBCollection.java
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);
    }
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.

@param keys   a document that contains pairs with the name of the field or fields to index and order of the index
@param name   an identifier for the index. If null or empty, the default name will be used.
@param unique if the index should be unique
@throws MongoException if the operation failed
@mongodb.driver.manual /administration/indexes-creation/ Index Creation Tutorials