@Nullable private IndexInfo fetchIndexInformation(@Nullable IndexDefinitionHolder indexDefinition) { if (indexDefinition == null) { return null; } try { IndexOperations indexOperations = indexOperationsProvider.indexOps(indexDefinition.getCollection()); Object indexNameToLookUp = indexDefinition.getIndexOptions().get("name"); List<IndexInfo> existingIndexes = indexOperations.getIndexInfo(); return existingIndexes.stream().// filter(indexInfo -> ObjectUtils.nullSafeEquals(indexNameToLookUp, indexInfo.getName())).// findFirst().// orElse(null); } catch (Exception e) { LOGGER.debug( String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()), e); } return null; } }
? ((Document) sourceDocument.get("partialFilterExpression")).toJson() : null; IndexInfo info = new IndexInfo(indexFields, name, unique, sparse, language); info.partialFilterExpression = partialFilter; info.collation = sourceDocument.get("collation", Document.class);
private Mono<IndexInfo> fetchIndexInformation(IndexDefinitionHolder indexDefinition) { Object indexNameToLookUp = indexDefinition.getIndexOptions().get("name"); Flux<IndexInfo> existingIndexes = operationsProvider.indexOps(indexDefinition.getCollection()).getIndexInfo(); return existingIndexes // .filter(indexInfo -> ObjectUtils.nullSafeEquals(indexNameToLookUp, indexInfo.getName())) // .next() // .doOnError(e -> { LOGGER.debug( String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()), e); }); }
? ((Document) sourceDocument.get("partialFilterExpression")).toJson() : null; IndexInfo info = new IndexInfo(indexFields, name, unique, sparse, language); info.partialFilterExpression = partialFilter; info.collation = sourceDocument.get("collation", Document.class);
@Nullable private IndexInfo fetchIndexInformation(@Nullable IndexDefinitionHolder indexDefinition) { if (indexDefinition == null) { return null; } try { IndexOperations indexOperations = indexOperationsProvider.indexOps(indexDefinition.getCollection()); Object indexNameToLookUp = indexDefinition.getIndexOptions().get("name"); List<IndexInfo> existingIndexes = indexOperations.getIndexInfo(); return existingIndexes.stream().// filter(indexInfo -> ObjectUtils.nullSafeEquals(indexNameToLookUp, indexInfo.getName())).// findFirst().// orElse(null); } catch (Exception e) { LOGGER.debug( String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()), e); } return null; } }
private Mono<IndexInfo> fetchIndexInformation(IndexDefinitionHolder indexDefinition) { Object indexNameToLookUp = indexDefinition.getIndexOptions().get("name"); Flux<IndexInfo> existingIndexes = operationsProvider.indexOps(indexDefinition.getCollection()).getIndexInfo(); return existingIndexes // .filter(indexInfo -> ObjectUtils.nullSafeEquals(indexNameToLookUp, indexInfo.getName())) // .next() // .doOnError(e -> { LOGGER.debug( String.format("Failed to load index information for collection '%s'.", indexDefinition.getCollection()), e); }); }
private boolean indexNotExists(final String name) { List<IndexInfo> indexes = mongoTemplate.indexOps(collectionName).getIndexInfo(); for (IndexInfo indexInfo : indexes) { if (name.equals(indexInfo.getName())) { return false; } } return true; }
/** * Method ensures that there is a TTL index on {@literal expireAt} field. It's has * {@literal expireAfterSeconds} set to zero seconds, so the expiration time is * controlled by the application. * * It can be extended in custom converters when there is a need for creating * additional custom indexes. * @param sessionCollectionIndexes {@link IndexOperations} to use */ protected void ensureIndexes(IndexOperations sessionCollectionIndexes) { for (IndexInfo info : sessionCollectionIndexes.getIndexInfo()) { if (EXPIRE_AT_FIELD_NAME.equals(info.getName())) { LOG.debug("TTL index on field " + EXPIRE_AT_FIELD_NAME + " already exists"); return; } } LOG.info("Creating TTL index on field " + EXPIRE_AT_FIELD_NAME); sessionCollectionIndexes .ensureIndex(new Index(EXPIRE_AT_FIELD_NAME, Sort.Direction.ASC).named(EXPIRE_AT_FIELD_NAME).expire(0)); }