MongoCollection 到 Java 列表

问题描述

我有一个看起来像这样的 Java 对象:

public class Partner {
    private String partnerName;
    private String partnerRef;
    private Site sites;

我将此作为文档存储在 MongoDB 中。我正在尝试像这样检索它:

    public List<Partner> getAllPartners(
            MongoCollection<Partner> partnerCollection) {
        List<Partner> partnerList = new ArrayList<>();
        return partnerCollection.find().into(partnerList);
    }

我不断收到以下错误

"message": "An exception occurred when decoding using the AutomaticPojoCodec.\nDecoding into a 'Partner' Failed with the following exception:\n\nFailed to decode 'Partner'. Decoding 'sites' errored with: readStartDocument can only be called when CurrentBSONType is DOCUMENT,not when CurrentBSONType is ARRAY.\n\nA custom Codec or PojoCodec may need to be explicitly configured and registered to handle this type.",

我认为这是由于 Partner Object 中的 Site 对象造成的,但我终生无法弄清楚如何解决这个问题。

请帮忙!

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...