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

前端 未结 8 781
渐次进展
渐次进展 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 01:09

    I resolve it by adding the spring-boot-starter-data-mongodb dependency in your pom.xml or your build.gradle.

    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.2.4.RELEASE'

    0 讨论(0)
  • 2020-12-11 01:14

    Documentation: MongoDB Driver Quick Start - POJOs

    After following the above document, if you are still getting error, then

    you could be using a generic document inside your collection like

    class DocStore {
      String docId:
      String docType;
      Object document; // this will cause the BSON cast to throw a codec error
      Map<String, Object> document; // this won't
    }
    

    And still, you would want to cast your document from POJO to Map

    mkyong tutorial could help.

    As for the fetch, it works as expected but you might want to cast from Map to your POJO as a post-processing step, we can find some good answers here

    Hope it helps!

    0 讨论(0)
提交回复
热议问题