code: private void createIndex(long idleTime) {
          try {
              this.sessions.createIndex(
                      new Document(SESSION_TTL, 1),
                      new IndexOptions()
                      .expireAfter(idleTime, TimeUnit.SECONDS)
                      .name(SESSION_INDEX_NAME));
          } catch (MongoException ex) {//update idle time
              this.sessions.dropIndex(SESSION_INDEX_NAME);
              this.sessions.createIndex(
                      new Document(SESSION_TTL, 1),
                      new IndexOptions()
                      .expireAfter(idleTime, TimeUnit.SECONDS)
                      .name(SESSION_INDEX_NAME));
          }
      }
docs: Create TTL index
  
  @param idleTime idle time in seconds
  @see <a href="https://docs.mongodb.com/manual/core/index-ttl/">Mongo docs</a>