driver-core/src/main/com/mongodb/client/model/IndexOptions.java
public IndexOptions expireAfter(@Nullable final Long expireAfter, final TimeUnit timeUnit) {
        if (expireAfter == null) {
            this.expireAfterSeconds = null;
        } else {
            this.expireAfterSeconds = TimeUnit.SECONDS.convert(expireAfter, timeUnit);
        }
        return this;
    }
public IndexOptions expireAfter(@Nullable final Long expireAfter, final TimeUnit timeUnit) {
        if (expireAfter == null) {
            this.expireAfterSeconds = null;
        } else {
            this.expireAfterSeconds = TimeUnit.SECONDS.convert(expireAfter, timeUnit);
        }
        return this;
    }
Sets the time to live for documents in the collection

@param expireAfter the time to live for documents in the collection
@param timeUnit the time unit for expireAfter
@return this
@mongodb.driver.manual tutorial/expire-data TTL