mongodb indexing spring boot code example

Example 1: mongodb spring boot index usage 0

spring.data.mongodb.auto-index-creation = true

Example 2: mongodb spring boot index usage 0

MongoDatabaseFactory dbFactory = new SimpleMongoClientDatabaseFactory(...);
DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(dbFactory);

MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setAutoIndexCreation(true);                
// ...
mappingContext.afterPropertiesSet();

MongoTemplate template = new MongoTemplate(dbFactory, new MappingMongoConverter(dbRefResolver, mappingContext));

Tags:

Misc Example