@Override protected final RepositoryFactorySupport createRepositoryFactory() { RepositoryFactorySupport factory = getFactoryInstance(operations); if (createIndexesForQueryMethods) { factory.addQueryCreationListener( new IndexEnsuringQueryCreationListener(collectionName -> operations.indexOps(collectionName))); } return factory; }
@Override protected final RepositoryFactorySupport createRepositoryFactory() { RepositoryFactorySupport factory = getFactoryInstance(operations); if (createIndexesForQueryMethods) { factory.addQueryCreationListener( new IndexEnsuringQueryCreationListener(collectionName -> operations.indexOps(collectionName))); } return factory; }
/** * Do not use {@link org.springframework.data.mongodb.core.index.ReactiveIndexOperations} to ensure indexes exist. * Instead, get a blocking {@link IndexOperations} and use that instead, if possible. */ @Override public void afterPropertiesSet() { if (this.blockingMongoOperations != null) { IndexOperations indexOperations = this.blockingMongoOperations.indexOps(this.collectionName); this.mongoSessionConverter.ensureIndexes(indexOperations); } }
@Override public void afterPropertiesSet() { IndexOperations indexOperations = this.mongoOperations.indexOps(this.collectionName); this.mongoSessionConverter.ensureIndexes(indexOperations); }
@PostConstruct public void ensureTTLIndex() { mongoOperations.indexOps(RATE_LIMIT_COLLECTION).ensureIndex(new IndexDefinition() { @Override public Document getIndexKeys() { return new Document(FIELD_RESET_TIME, 1L); } @Override public Document getIndexOptions() { // To expire Documents at a Specific Clock Time we have to specify an expireAfterSeconds value of 0. return new Document("expireAfterSeconds", 0L); } }); }
@Override public ResourcesValidationResult validateResources() { ResourcesValidationResult.RESULT result = ResourcesValidationResult.RESULT.VALID; IndexOperations indexOperations = mongoTemplate.indexOps(collection); List<IndexInfo> indexes = indexOperations.getIndexInfo(); if (indexes.isEmpty()) { result = ResourcesValidationResult.RESULT.NOT_INITIALIZED; } return new ResourcesValidationResult(result); }
@Override public void dropResources() { IndexOperations indexOperations = mongoTemplate.indexOps(collection); indexOperations.dropAllIndexes(); mongoTemplate.dropCollection(collection); } }
@Autowired public void ensureIndexes(MongoOperations mongo) { LOG.info("Creating token mongo indexes"); mongo.indexOps(OneTimeAccessToken.class).ensureIndex( new MongoIndex().on("expireAt", Direction.ASC).expires(0, TimeUnit.SECONDS).background() .getIndexDefinition()); } }
@Autowired public void ensureIndexes(MongoOperations mongo) { LOG.info("Creating token mongo indexes"); mongo.indexOps(OneTimeAccessToken.class).ensureIndex( new MongoIndex().on("expireAt", Direction.ASC).expires(0, TimeUnit.SECONDS).background() .getIndexDefinition()); } }
@Autowired public void ensureIndexes(MongoOperations mongo) { LOG.info("Creating token mongo indexes"); mongo.indexOps(OneTimeAccessToken.class).ensureIndex( new MongoIndex().on("expireAt", Direction.ASC).expires(0, TimeUnit.SECONDS).background() .getIndexDefinition()); } }
private void ensureIndex() { IndexOperations indexOperations = mongoTemplate.indexOps(collection); indexOperations.ensureIndex(new Index().on("key", Direction.ASC).unique()); }