Bson pretty print using Java MongoDb driver

后端 未结 3 1920
暗喜
暗喜 2021-01-06 11:52

I am using the Mongo Aggregation Framework using the Java MongoDB driver, version 3.3. I have an aggregagtion pipeline, that is merely collection of type List

3条回答
  •  伪装坚强ぢ
    2021-01-06 12:07

    This is a rather old question, however I put my suggestion (for mongodb-driver 3.6.4) here as this is the most relevant post when googling on "mongodb java driver pretty print":

    BsonDocument bsonDocument = bson.toBsonDocument(BsonDocument.class, MongoClient.getDefaultCodecRegistry());
    JsonWriterSettings.Builder settingsBuilder = JsonWriterSettings.builder().indent(true);
    System.out.println(bsonDocument.toJson(settingsBuilder.build());
    

提交回复
热议问题