code: public static void addTTLIndex(DBCollection collection, String field, int ttl) {
          if (ttl <= 0) {
              throw new IllegalArgumentException("TTL must be positive");
          }
          collection.createIndex(new BasicDBObject(field, 1), new BasicDBObject("expireAfterSeconds", ttl));
      }
docs: adds a TTL index to the given collection. The TTL must be a positive integer.
  
  @param collection the collection to use for the TTL index
  @param field      the field to use for the TTL index
  @param ttl        the TTL to set on the given field
  @throws IllegalArgumentException if the TTL is less or equal 0