Resolve DBRef into Json

后端 未结 2 1803
清酒与你
清酒与你 2021-01-18 12:36

I\'m getting the following error in a Normalized Data Model structure in MongoDB:

org.bson.codecs.configuration.CodecConfigurationException: Can\'t find a co         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-18 13:15

    You have to import the DBRef Codec for it to print it, if u want it in a document json style you need to write your own Codec for DBRef and add it to the codecregistry you give toJson().

    e.g.

    CodecRegistry codecRegistry = CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry());
    -------
    final DocumentCodec codec = new DocumentCodec(codecRegistry, new BsonTypeClassMap());
    -------
    System.out.println(document.toJson(codec));
    

提交回复
热议问题