_class attribute in Spring data MongoDB_
Spring data MongoDB adds a _class
attribute to every document written to MongoDB
If we want to prvent adding Spring Data MongoDB from adding _class
attribute, we can configure this behaviour through:
@Configuration
public class MongoConfig extends AbstractMongoClientConfiguration {
@Override
protected boolean autoIndexCreation() {
return true;
}
@Bean
public MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory databaseFactory, MongoMappingContext mappingContext) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(databaseFactory);
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mappingContext);
converter.setTypeMapper(new DefaultMongoTypeMapper(null));
return converter;
}
}