MongoDB org.bson.Document to POJO

时间:2018-02-15 14:03:12

标签: java mongodb mongodb-query

我使用mongo驱动程序3.6.2当我尝试将返回值转换为POJO列表时,返回列表为空:

CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
CodecRegistry pojoCodecRegistry = fromRegistries(mongoClientProvider.getMongoClient().getDefaultCodecRegistry(), fromProviders(pojoCodecProvider));

MongoDatabase database = mongoClientProvider.getMongoClient().getDatabase(DATABASE_NAME).withCodecRegistry(pojoCodecRegistry);
MongoCollection<POJO> collection = database.getCollection(Constants.COLLECTION_NAME, POJO.class);  

List<POJO> results = collection.find().into(new ArrayList<POJO>());

Mongo司机

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.6.2</version>
</dependency>

0 个答案:

没有答案