久しぶりに、
3.0 からIndexOptions
と
index 作成が
参考
MongoDB java driver の version
3.2.2
です。
<!-- MongoDB --> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.2.2</version> </dependency>
実装
- TTL index を
作成する
IndexOptions を
Indexes を
IndexOptions createdAtIndexOptions = new IndexOptions() .expireAfter(settings.getExpirationTime(), TimeUnit.MINUTES) .background(true) .name("createdAt_ttl_index"); Bson createdAt = Indexes.ascending("createdAt"); collection.createIndex(createdAt, createdAtIndexOptions);
以前の
以上です。
コメント