我有一个看起来像这样的 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.",
我认为这是由于合作伙伴对象中的站点对象而发生的,但我终生无法弄清楚如何解决此问题。