Mongodb存储和检索对象列表POJO失败

时间:2019-03-17 18:04:59

标签: java mongodb pojo

我有以下POJO,其中有

的列表
public class NewBuildRequestDAO {

@BsonId private ObjectId id ;
@BsonProperty("platform_id") private String platform_id;
@BsonProperty("build_submit_type") private String build_submit_type;
@BsonProperty("file_path") private String file_path;
@BsonProperty("comments") private List<QERequestComments> comments;

但是当我尝试检索评论部分时,出现以下异常:

org.bson.codecs.configuration.CodecConfigurationException: An 
exception occurred when decoding using the AutomaticPojoCodec.
Decoding into a 'NewBuildRequestDAO' failed with the following exception:

Failed to decode 'NewBuildRequestDAO'. Decoding 'comments' errored 
with: readStartArray can only be called when CurrentBSONType is ARRAY, 
not when CurrentBSONType is DOCUMENT.

A custom Codec or `PojoCodec` may need to be explicitly configured and registered to handle this type.
org.bson.codecs.pojo.AutomaticPojoCodec.decode(AutomaticPojoCodec.java:40)
com.mongodb.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52)

有人知道如何以pojo方式将对象列表存储到Mongodb以及如何检索对象列表吗?

0 个答案:

没有答案