/** * Get a list of index names for the given list of index models * * @param indexes the index models * @param codecRegistry the codec registry to convert each Bson key to a BsonDocument * @return the list of index names */ public static List<String> getIndexNames(final List<IndexModel> indexes, final CodecRegistry codecRegistry) { List<String> indexNames = new ArrayList<String>(indexes.size()); for (IndexModel index : indexes) { String name = index.getOptions().getName(); if (name != null) { indexNames.add(name); } else { indexNames.add(IndexHelper.generateIndexName(index.getKeys().toBsonDocument(BsonDocument.class, codecRegistry))); } } return indexNames; }
.name(model.getOptions().getName()) .background(model.getOptions().isBackground()) .unique(model.getOptions().isUnique()) .sparse(model.getOptions().isSparse()) .expireAfter(model.getOptions().getExpireAfter(TimeUnit.SECONDS), TimeUnit.SECONDS) .version(model.getOptions().getVersion()) .weights(toBsonDocument(model.getOptions().getWeights())) .defaultLanguage(model.getOptions().getDefaultLanguage()) .languageOverride(model.getOptions().getLanguageOverride()) .textVersion(model.getOptions().getTextVersion()) .sphereVersion(model.getOptions().getSphereVersion()) .bits(model.getOptions().getBits()) .min(model.getOptions().getMin()) .max(model.getOptions().getMax()) .bucketSize(model.getOptions().getBucketSize()) .storageEngine(toBsonDocument(model.getOptions().getStorageEngine())) .partialFilterExpression(toBsonDocument(model.getOptions().getPartialFilterExpression())) .collation(model.getOptions().getCollation()) );
/** * Get a list of index names for the given list of index models * * @param indexes the index models * @param codecRegistry the codec registry to convert each Bson key to a BsonDocument * @return the list of index names */ public static List<String> getIndexNames(final List<IndexModel> indexes, final CodecRegistry codecRegistry) { List<String> indexNames = new ArrayList<String>(indexes.size()); for (IndexModel index : indexes) { String name = index.getOptions().getName(); if (name != null) { indexNames.add(name); } else { indexNames.add(IndexHelper.generateIndexName(index.getKeys().toBsonDocument(BsonDocument.class, codecRegistry))); } } return indexNames; }
.name(model.getOptions().getName()) .background(model.getOptions().isBackground()) .unique(model.getOptions().isUnique()) .sparse(model.getOptions().isSparse()) .expireAfter(model.getOptions().getExpireAfter(TimeUnit.SECONDS), TimeUnit.SECONDS) .version(model.getOptions().getVersion()) .weights(toBsonDocument(model.getOptions().getWeights())) .defaultLanguage(model.getOptions().getDefaultLanguage()) .languageOverride(model.getOptions().getLanguageOverride()) .textVersion(model.getOptions().getTextVersion()) .sphereVersion(model.getOptions().getSphereVersion()) .bits(model.getOptions().getBits()) .min(model.getOptions().getMin()) .max(model.getOptions().getMax()) .bucketSize(model.getOptions().getBucketSize()) .storageEngine(toBsonDocument(model.getOptions().getStorageEngine())) .partialFilterExpression(toBsonDocument(model.getOptions().getPartialFilterExpression())) .collation(model.getOptions().getCollation()) );
Map<String, Object> indexOptionsMap = new HashMap<>(); List<Document> expectedIndexDocuments = expectedIndices.stream().map(expectedIndex -> { IndexOptions expectedIndexOptions = expectedIndex.getOptions(); indexOptionsMap.put("key", expectedIndex.getKeys());
/** * Creates the specified index. Throws an exception if the index with the same name already exists. * * <p> * Just does nothing if another index for the same keys with conflicting options already exists. For details, see * the <a href="https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/">MongoDB documentation</a>. * </p> * * @param collectionName the name of the collection containing the index. * @param index the index. * @return a source which emits {@link Success}. */ public Source<Success, NotUsed> createIndex(final String collectionName, final Index index) { final IndexModel indexModel = index.toIndexModel(); return Source.fromPublisher(getCollection(collectionName).createIndex(indexModel.getKeys(), indexModel .getOptions())).map(unused -> Success.SUCCESS); }
/** * Creates the specified index. Throws an exception if the index with the same name already exists. * * <p> * Just does nothing if another index for the same keys with conflicting options already exists. For details, see * the <a href="https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/">MongoDB documentation</a>. * </p> * * @param collectionName the name of the collection containing the index. * @param index the index. * @return a source which emits {@link Success}. */ public Source<Success, NotUsed> createIndex(final String collectionName, final Index index) { final IndexModel indexModel = index.toIndexModel(); return Source.fromPublisher(getCollection(collectionName).createIndex(indexModel.getKeys(), indexModel .getOptions())).map(unused -> Success.SUCCESS); }