/** * Configures name for an index, that is otherwise will be auto-named by index fields. * @param indexName explicitly provided index name * @return {@code this} indexer for chained invocation */ // safe unchecked: we expect I to be a self type @SuppressWarnings("unchecked") public final I named(String indexName) { options.name(indexName); return (I) this; }
private static void createIndex(MongoConnection mongoConnection) { final IndexOptions indexOptions = new IndexOptions() .name(INDEX_NAME) .unique(true); mongoConnection.getMongoDatabase() .getCollection(COLLECTION_NAME) .createIndex(Indexes.ascending("name"), indexOptions); }
private void syncTtl() { if (!ttlSync.get()) { ttlSync.set(true); if (timeout <= 0) { return; } log.debug("creating session timeout index"); if (existsIdx(SESSION_IDX)) { Document command = new Document("collMod", collection) .append("index", new Document("keyPattern", new Document("_accessedAt", 1)) .append("expireAfterSeconds", timeout)); log.debug("{}", command); Document result = db.runCommand(command); log.debug("{}", result); } else { sessions.createIndex( new Document("_accessedAt", 1), new IndexOptions() .name(SESSION_IDX) .expireAfter(timeout, TimeUnit.SECONDS)); } } }
.name(MongoDbGrokPatternService.INDEX_NAME) .unique(true); collection.createIndex(Indexes.ascending("name"), indexOptions);
@SuppressWarnings("deprecation") com.mongodb.client.model.IndexOptions convert(final IndexOptions options, final boolean background) { if (options.dropDups()) { LOG.warn("Support for dropDups has been removed from the server. Please remove this setting."); } com.mongodb.client.model.IndexOptions indexOptions = new com.mongodb.client.model.IndexOptions() .background(options.background() || background) .sparse(options.sparse()) .unique(options.unique()); if (!options.language().equals("")) { indexOptions.defaultLanguage(options.language()); } if (!options.languageOverride().equals("")) { indexOptions.languageOverride(options.languageOverride()); } if (!options.name().equals("")) { indexOptions.name(options.name()); } if (options.expireAfterSeconds() != -1) { indexOptions.expireAfter((long) options.expireAfterSeconds(), TimeUnit.SECONDS); } if (!options.partialFilter().equals("")) { indexOptions.partialFilterExpression(Document.parse(options.partialFilter())); } if (!options.collation().locale().equals("")) { indexOptions.collation(convert(options.collation())); } return indexOptions; }
ops = ops.name(indexOptions.get("name").toString());
/** * Create TTL index * * @param idleTime idle time in seconds * @see https://docs.mongodb.com/manual/core/index-ttl/ */ 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)); } }
@Override public IndexOptions convert(Environment env, TraceInfo trace, Memory arg) throws Throwable { if (arg.isNull()) return null; ArrayMemory arr = arg.toValue(ArrayMemory.class); IndexOptions options = new IndexOptions(); if (arr.containsKey("background")) { options.background(arg.valueOfIndex("background").toBoolean()); } if (arr.containsKey("defaultLanguage")) { options.defaultLanguage(arg.valueOfIndex("defaultLanguage").toString()); } if (arr.containsKey("bits")) { options.bits(arg.valueOfIndex("bits").toInteger()); } if (arr.containsKey("name")) { options.name(arg.valueOfIndex("name").toString()); } if (arr.containsKey("max")) { options.max(arg.valueOfIndex("max").toDouble()); } if (arr.containsKey("min")) { options.min(arg.valueOfIndex("min").toDouble()); } if (arr.containsKey("languageOverride")) { options.languageOverride(arg.valueOfIndex("languageOverride").toString()); } if (arr.containsKey("sparse")) { options.sparse(arg.valueOfIndex("sparse").toBoolean()); } if (arr.containsKey("unique")) { options.unique(arg.valueOfIndex("unique").toBoolean()); } if (arr.containsKey("version")) { options.version(arg.valueOfIndex("version").toInteger()); } if (arr.containsKey("textVersion")) { options.textVersion(arg.valueOfIndex("textVersion").toInteger()); } if (arr.containsKey("sphereVersion")) { options.sphereVersion(arg.valueOfIndex("sphereVersion").toInteger()); } return options; }
/** * Configures name for an index, that is otherwise will be auto-named by index fields. * @param indexName explicitly provided index name * @return {@code this} indexer for chained invocation */ // safe unchecked: we expect I to be a self type @SuppressWarnings("unchecked") public final I named(String indexName) { options.name(indexName); return (I) this; }
ops = ops.name(indexOptions.get("name").toString());
private void createCollectionAndUniqueIndexIfNotExists(MongoDatabase db) { Document indexKeys = new Document(KEY_PROP_NAME, INDEX_SORT_ASC); IndexOptions indexOptions = new IndexOptions().unique(true).name("mongobeelock_key_idx"); db.getCollection(lockCollectionName).createIndex(indexKeys, indexOptions); }
private void createCollectionAndUniqueIndexIfNotExists(MongoDatabase db) { Document indexKeys = new Document(KEY_PROP_NAME, INDEX_SORT_ASC); IndexOptions indexOptions = new IndexOptions().unique(true).name("mongobeelock_key_idx"); db.getCollection(lockCollectionName).createIndex(indexKeys, indexOptions); }
/** * Create index on billing collection. * * @param indexName the name of index. * @param index the index options. */ private void createBillingIndexes(String indexName, Bson index) { MongoCollection<Document> collection = database.getCollection(MongoConstants.COLLECTION_BILLING); IndexOptions options = new IndexOptions().name(MongoConstants.COLLECTION_BILLING + indexName); try { collection .createIndex(index, options); } catch (Exception e) { LOGGER.warn("Cannot create index {} on collection {}. {}", options.getName(), MongoConstants.COLLECTION_BILLING, e.getLocalizedMessage(), e); } }
@Override public void ensureIndexes(MongoCollection<Document> eventsCollection, MongoCollection<Document> snapshotsCollection) { eventsCollection.createIndex(new BasicDBObject(eventConfiguration.aggregateIdentifierProperty(), ORDER_ASC) .append(eventConfiguration.sequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(true).name("uniqueAggregateIndex")); eventsCollection.createIndex(new BasicDBObject(eventConfiguration.timestampProperty(), ORDER_ASC) .append(eventConfiguration.sequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(false).name("orderedEventStreamIndex")); snapshotsCollection.createIndex(new BasicDBObject(eventConfiguration.aggregateIdentifierProperty(), ORDER_ASC) .append(eventConfiguration.sequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(true).name("uniqueAggregateIndex")); }
@Override public void ensureIndexes(MongoCollection<Document> eventsCollection, MongoCollection<Document> snapshotsCollection) { eventsCollection.createIndex(new BasicDBObject(eventConfiguration.aggregateIdentifierProperty(), ORDER_ASC) .append(eventConfiguration.sequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(true).name("uniqueAggregateIndex")); eventsCollection.createIndex(new BasicDBObject(eventConfiguration.timestampProperty(), ORDER_ASC) .append(eventConfiguration.sequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(false).name("orderedEventStreamIndex")); snapshotsCollection.createIndex(new BasicDBObject(eventConfiguration.aggregateIdentifierProperty(), ORDER_ASC) .append(eventConfiguration.sequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(true).name("uniqueAggregateIndex")); }
@Override public void ensureIndexes(MongoCollection<Document> eventsCollection, MongoCollection<Document> snapshotsCollection) { super.ensureIndexes(eventsCollection, snapshotsCollection); //prevents duplicate commits eventsCollection.createIndex(new BasicDBObject(eventConfiguration().aggregateIdentifierProperty(), ORDER_ASC) .append(commitEntryConfiguration.firstSequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(true).name("uniqueAggregateStartIndex")); } }
@Override public void ensureIndexes(MongoCollection<Document> eventsCollection, MongoCollection<Document> snapshotsCollection) { super.ensureIndexes(eventsCollection, snapshotsCollection); //prevents duplicate commits eventsCollection.createIndex(new BasicDBObject(eventConfiguration().aggregateIdentifierProperty(), ORDER_ASC) .append(commitEntryConfiguration.firstSequenceNumberProperty(), ORDER_ASC), new IndexOptions().unique(true).name("uniqueAggregateStartIndex")); } }
/** * Creates a new {@link IndexModel}, which can be used for creating indices using MongoDB Java drivers. * * @return the created {@link IndexModel} */ public IndexModel toIndexModel() { final IndexOptions options = new IndexOptions() .name(name) .unique(unique) .sparse(sparse) .background(background); if (!partialFilterExpression.isEmpty()) { options.partialFilterExpression(partialFilterExpression); } return new IndexModel(keys, options); }
/** * Creates a new {@link IndexModel}, which can be used for creating indices using MongoDB Java drivers. * * @return the created {@link IndexModel} */ public IndexModel toIndexModel() { final IndexOptions options = new IndexOptions() .name(name) .unique(unique) .sparse(sparse) .background(background); if (!partialFilterExpression.isEmpty()) { options.partialFilterExpression(partialFilterExpression); } return new IndexModel(keys, options); }
public QueryResult createIndex(Bson keys, ObjectMap options) { long start = startQuery(); IndexOptions i = new IndexOptions(); if (options.containsKey(UNIQUE)) { i.unique(options.getBoolean(UNIQUE)); } if (options.containsKey(BACKGROUND)) { i.background(options.getBoolean(BACKGROUND)); } if (options.containsKey(SPARSE)) { i.sparse(options.getBoolean(SPARSE)); } if (options.containsKey(NAME)) { i.name(options.getString(NAME)); } mongoDBNativeQuery.createIndex(keys, i); QueryResult queryResult = endQuery(Collections.emptyList(), start); return queryResult; }