mongo db 去除 _class 字段
Posted lykbk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongo db 去除 _class 字段相关的知识,希望对你有一定的参考价值。
-
import org.springframework.beans.factory.BeanFactory;
-
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-
import org.springframework.context.annotation.Bean;
-
import org.springframework.context.annotation.Configuration;
-
import org.springframework.data.convert.CustomConversions;
-
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;
-
-
/**
-
* Create by JIUN·LIU at 2018/7/24
-
*/
-
-
-
public class MongoConfig
-
-
-
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, BeanFactory beanFactory)
-
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
-
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
-
try
-
mappingConverter.setCustomConversions(beanFactory.getBean(CustomConversions.class));
-
catch (NoSuchBeanDefinitionException ignore)
-
-
-
// Don‘t save _class to mongo
-
mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
-
-
return mappingConverter;
-
-
-
以上是关于mongo db 去除 _class 字段的主要内容,如果未能解决你的问题,请参考以下文章