title: Couldn't find PersistentEntity for type class when using @EnableMongoAuditing
body: <p>I am getting "<strong>Couldn't find PersistentEntity for type class</strong>" error when I am using <code>@EnableMongoAuditing</code> features along with MongoRepository.
  This happens when I save a document when collection isn't already present in database.</p>
  
  <p>I tried whatever is mentioned in:</p>
  
  <ul>
  <li><a href="https://github.com/spring-projects/spring-boot/issues/12023" rel="noreferrer">https://github.com/spring-projects/spring-boot/issues/12023</a></li>
  <li><a href="https://jira.spring.io/browse/DATAMONGO-1999" rel="noreferrer">https://jira.spring.io/browse/DATAMONGO-1999</a></li>
  <li><a href="https://stackoverflow.com/questions/46863819/spring-boot-mongodb-auditing-error">Spring boot mongodb auditing error</a></li>
  </ul>
  
  <p>but nothing is working.</p>
  
  <p>Mentioned things are:</p>
  
  <p>Extend MongoConfig by AbstractMongoConfiguration and override all methods.</p>
  
  <p>Here is my code which reproduced the same error:</p>
  
  <p><strong>MongoConfig class</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  public class MongoConfig extends AbstractMongoConfiguration {
  
      @Value("${spring.data.mongodb.host}")
      private String mongoHost;
  
      @Value("${spring.data.mongodb.port}")
      private String mongoPort;
  
      @Value("${spring.data.mongodb.database}")
      private String mongoDB;
  
      @Override
      public MongoDbFactory mongoDbFactory() {
          return new SimpleMongoDbFactory(new MongoClient(mongoHost + ":" + mongoPort), mongoDB);
      }
  
      @Override
      public MongoClient mongoClient() {
          return new MongoClient(mongoHost, Integer.parseInt(mongoPort));
      }
  
      @Override
      public MongoTemplate mongoTemplate() {
          return new MongoTemplate(mongoDbFactory());
      }
  
      @Override
      public MappingMongoConverter mappingMongoConverter() {
          return new MappingMongoConverter(new DefaultDbRefResolver(mongoDbFactory()), new MongoMappingContext());
      }
  
      @Override
      protected String getDatabaseName() {
          return mongoDB;
      }
  }
  </code></pre>
  
  <p><strong>Person Collection class</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@Document
  public class Person {
      @Id
      private String id;
  
      private String name;
  
      @CreatedDate
      private LocalDateTime createdAt;
      @LastModifiedDate
      private LocalDateTime lastModified;
      // Getter Setters Constructors omitted for brevity
  }
  </code></pre>
  
  <p><strong>Main Application class</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>@EnableMongoAuditing
  @EnableMongoRepositories ({"com.example.*", "org.apache.*"})
  @SpringBootApplication
  @ComponentScan({"com.example.*", "org.apache.*"})
  public class DemoApplication implements CommandLineRunner {
  
      @Autowired
      PersonRepository personRepository;
      public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
      }
  
      @Override
      public void run(String... args) throws Exception {
          Person p1 = new Person("1", "prakhar");
          personRepository.save(p1);
  
      }
  }
  </code></pre>
  
  <p>Expected Result is Person entity should be saved in database.
  Actual Result is "<strong>Couldn't find PersistentEntity for type class Person</strong>" error</p>