MongoDB Java Inserting Throws org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class io.github.ilkgunel.mongodb.Pojo

前端 未结 8 792
渐次进展
渐次进展 2020-12-11 00:25

I\'m learning MongoDB with Java. I\'m trying to insert data to MongoDB with Java driver. I\'m doing inserting like in MongoDB tutorial and every thing is okey. But if I want

8条回答
  •  轮回少年
    2020-12-11 00:58

    To be bit abstract, as this may save the day for other developers..
    This error: CodecConfigurationException: Can't find a codec for class xxx means that your mongo driver is not able to handle the data you sent in the object you made of that xxx class and accordingly can't generate the mongo query you want.

    The resolution in that case would be either to use the right class i.e to use one of the expected classes by the driver (in my case replacing java array by ArrayList object resolved the issue).. The other resolution could be to upgrade your driver. Third solution could be as mentioned by @Renato, to define your own decoding logic.. This depends on your exact case.
    hth

提交回复
热议问题