title: Remove "_class" from MongoDB - Springboot
body: <p>I am new to SpringBoot and I am trying to connect my SpringBoot App to MongoDB. The GET Request is working completely fine but the POST Request is adding a &quot;_class&quot; field in the data which I don't want. I did some searching and found that I have to add a @Configuration class to solve this issue but when I added the @Configuration class, I am getting the following error :</p>
  <pre><code>Field mongoDbFactory in com.example.demo.configuration.MongoConfig required a bean of type 'org.springframework.data.mongodb.MongoDbFactory' that could not be found.
  </code></pre>
  <p>My Confuguration class code is as follows :-</p>
  <p>MongoConfig.java :-</p>
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.data.mongodb.MongoDbFactory;
  import org.springframework.data.mongodb.core.convert.DbRefResolver;
  import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
  import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
  import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
  import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
  
  @Configuration
  public class MongoConfig {
      @Autowired
      private MongoDbFactory mongoDbFactory;
  
      @Autowired
      private MongoMappingContext mongoMappingContext;
  
      @Bean
      public MappingMongoConverter mappingMongoConverter() {
  
          DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDbFactory);
          MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, 
  mongoMappingContext);
          converter.setTypeMapper(new DefaultMongoTypeMapper(null));
  
          return converter;
      }
  }
  </code></pre>
  <p>Controller.java :-</p>
  <pre><code>import com.example.demo.model.Todo;
  import com.example.demo.services.TodoService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RestController;
  
  import java.util.List;
  
  @RestController
  public class Controller {
  
      @Autowired
      private TodoService todoService;
  
      @GetMapping(&quot;/&quot;)
      public List&lt;Todo&gt; getTodos() {
          return todoService.getTodos();
      }
  
      @PostMapping(&quot;/&quot;)
      public Todo addTodo(@RequestBody Todo todo) {
          return  todoService.addTodo(todo);
      }
  
  }
  </code></pre>
  <p>TodoService.java :-</p>
  <pre><code>import com.example.demo.model.Todo;
  
  import java.util.List;
  
  public interface TodoService {
  
      public List&lt;Todo&gt; getTodos();
  
      public Todo addTodo(Todo todo);
  
  }
  </code></pre>
  <p>TodoServiceImplementation.java :-</p>
  <pre><code>import com.example.demo.model.Todo;
  import com.example.demo.repository.TodoRepository;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import java.util.List;
  
  @Service
  public class TodoServiceImplementation implements TodoService{
  
   @Autowired
   private TodoRepository todoRepository;
  
   @Override
   public List&lt;Todo&gt; getTodos() {
       return todoRepository.findAll();
   }
  
   @Override
   public Todo addTodo(Todo todo) {
       return todoRepository.save(todo);
   }
  
   }
  </code></pre>