In one of my project I am also facing a similar issue and AbstractMongoClientConfiguration class does not contain the method autoIndexCreation. Kindly suggest me way. I have made spring.data.mongodb.auto-index-creation = true in application.properties and not used in "AbstractMongoClientConfiguration" in any of sub class.

Comment From: wilkinsona

The method is still there. Note that it's inherited from MongoConfigurationSupport, the superclass of AbstractMongoClientConfiguration.

Unfortunately, from the little you have described, I can't tell why setting spring.data.mongodb.auto-index-creation to true did not work. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: karnsweta92

After overriding the method still it does not work. When I tried it after extending the class and it asked me to implement the following method:

  @Override
  protected String getDatabaseName() {
    return null;
  }

I did it as:

public class CustomMongoConfiguration extends AbstractMongoClientConfiguration {

  @Autowired
  Environment env;

  @Bean
  MongoDatabaseFactory mongoDatabaseFactory() {
    return new SimpleMongoClientDatabaseFactory(new ConnectionString(
        Objects.requireNonNull(env.getProperty("spring.data.mongodb.uri"))));
  }

  @Bean
  MongoTemplate mongoTemplate(@Autowired MongoDatabaseFactory databaseFactory) {
    return new MongoTemplate(databaseFactory);
  }

  @Override
  protected String getDatabaseName() {
    return "someDBName";
  }

  @Override
  protected boolean autoIndexCreation() {
    return true;
  }

}

still it did not work.

Comment From: wilkinsona

Thanks for the additional details. Unfortunately, there's still not enough information for us to be able to help you. For example, we don't know which version of Spring Boot you're using or how you've identified that the index creation isn't working. Can you please take the code snippet above and add it and anything else that's needed to reproduce the problem to a minimal application generated by https://start.spring.io and share it with us?

Comment From: karnsweta92

Sure, let me try. I am using Mongo version: 4.4 Spring boot version: 2.5.12 and It is an enterprise code so little difficult to share the reproducible sample code. Also the code shared here is causing error can you help here may be after it this will work.

Comment From: karnsweta92

waiting for response.

Comment From: wilkinsona

Open source support for Spring Boot 2.5.x ended in May 2022. Please upgrade to Spring Boot 2.7.x. If that does not help, we will require a minimal sample that reproduces the problem.

Spring boot version: 2.5.12 and It is an enterprise code so little difficult to share the reproducible sample code.

We don't need (or want) your enterprise code. As I said above, what we want is an application created using https://start.spring.io with the bare minimum needed to reproduce the problem added to it.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.