/** * 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; }
throw new IllegalArgumentException("indexes can not contain a null value"); indexRequests.add(new IndexRequest(toBsonDocument(model.getKeys())) .name(model.getOptions().getName()) .background(model.getOptions().isBackground())
/** * 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; }
List<Document> expectedIndexDocuments = expectedIndices.stream().map(expectedIndex -> { IndexOptions expectedIndexOptions = expectedIndex.getOptions(); indexOptionsMap.put("key", expectedIndex.getKeys()); ((Document) expectedIndex.getKeys()).forEach((key, value) -> indexName.append("_").append(key).append("_").append(value)); indexName.deleteCharAt(0);
/** * 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); }
throw new IllegalArgumentException("indexes can not contain a null value"); indexRequests.add(new IndexRequest(toBsonDocument(model.getKeys())) .name(model.getOptions().getName()) .background(model.getOptions().isBackground())