From 475ecccab1b75c730e5db994e72b2a254bba5f5d Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 11 May 2020 14:23:49 +0200 Subject: [PATCH] #553 - Upgrade Mongo/Rest examples to Spring Boot 2.3. --- .../example/springdata/rest/stores/StoreInitializer.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rest/starbucks/src/main/java/example/springdata/rest/stores/StoreInitializer.java b/rest/starbucks/src/main/java/example/springdata/rest/stores/StoreInitializer.java index 6a2bbe5f..979ee9d7 100644 --- a/rest/starbucks/src/main/java/example/springdata/rest/stores/StoreInitializer.java +++ b/rest/starbucks/src/main/java/example/springdata/rest/stores/StoreInitializer.java @@ -32,6 +32,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.data.geo.Point; import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.index.IndexDefinition; +import org.springframework.data.mongodb.core.index.IndexResolver; import org.springframework.stereotype.Component; /** @@ -51,6 +53,12 @@ public class StoreInitializer { return; } + Iterable indexDefinitions = IndexResolver + .create(operations.getConverter().getMappingContext()) + .resolveIndexFor(Store.class); + + indexDefinitions.forEach(operations.indexOps(Store.class)::ensureIndex); + List stores = readStores(); log.info("Importing {} stores into MongoDB…", stores.size()); repository.saveAll(stores);