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 ) ) ; } }
Create TTL index