code: 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));
      }
docs: Add an index on the given collection and field
  
  @param collection the collection to use for the index
  @param field      the field to use for the index
  @param asc        the sorting direction. <code>true</code> to sort ascending; <code>false</code> to sort descending
  @param background iff <code>true</code> the index is created in the background