本文整理汇总了Java中com.mongodb.client.model.IndexOptions.expireAfter方法的典型用法代码示例。如果您正苦于以下问题:Java IndexOptions.expireAfter方法的具体用法?Java IndexOptions.expireAfter怎么用?Java IndexOptions.expireAfter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.client.model.IndexOptions
的用法示例。
在下文中一共展示了IndexOptions.expireAfter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createIndex
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
protected void createIndex(String name, BasicDBList dbList, MongoCollection<Document> collection) {
if (dbList.isEmpty() || name == null) {
return;
}
BasicDBObject index = (BasicDBObject) dbList.get(0);
IndexOptions options = new IndexOptions().name(name);
if (dbList.size() > 1) {
BasicDBObject opts = (BasicDBObject) dbList.get(1);
if (opts.get("unique") != null && opts.get("unique") instanceof Boolean) {
options = options.unique(opts.getBoolean("unique"));
}
if (opts.get("expireAfterSeconds") != null && opts.get("expireAfterSeconds") instanceof Integer) {
options = options.expireAfter(Long.valueOf(opts.getInt("expireAfterSeconds")), TimeUnit.SECONDS);
}
if (opts.get("background") != null && opts.get("background") instanceof Boolean) {
options = options.background(opts.getBoolean("background"));
}
if (opts.get("bits") != null && opts.get("bits") instanceof Integer) {
options = options.bits(opts.getInt("bits"));
}
if (opts.get("bucketSize") != null && opts.get("bucketSize") instanceof Double) {
options = options.bucketSize(opts.getDouble("bucketSize"));
}
if (opts.get("defaultLanguage") != null && opts.get("defaultLanguage") instanceof String) {
options = options.defaultLanguage(opts.getString("defaultLanguage"));
}
if (opts.get("languageOverride") != null && opts.get("languageOverride") instanceof String) {
options = options.languageOverride(opts.getString("languageOverride"));
}
if (opts.get("min") != null && opts.get("min") instanceof Double) {
options = options.min(opts.getDouble("min"));
}
if (opts.get("max") != null && opts.get("max") instanceof Double) {
options = options.max(opts.getDouble("max"));
}
if (opts.get("sparse") != null && opts.get("sparse") instanceof Boolean) {
options = options.sparse(opts.getBoolean("sparse"));
}
if (opts.get("textVersion") != null && opts.get("textVersion") instanceof Integer) {
options = options.textVersion(opts.getInt("textVersion"));
}
if (opts.get("version") != null && opts.get("version") instanceof Integer) {
options = options.version(opts.getInt("version"));
}
if (opts.get("weights") != null && opts.get("weights") instanceof Bson) {
options = options.weights((Bson) opts.get("weights"));
}
}
collection.createIndex(new Document(index), options);
}
示例2: createTimestampIndexWithTTL
import com.mongodb.client.model.IndexOptions; //导入方法依赖的package包/类
private void createTimestampIndexWithTTL(MongoCollection<Document> collection, String attribute, Long ttl) {
IndexOptions options = new IndexOptions();
options.expireAfter(ttl, TimeUnit.SECONDS);
createTimestampIndexWithOptions(collection, attribute, options);
}