Bson pretty print using Java MongoDb driver

后端 未结 3 1917
暗喜
暗喜 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:25

    Googling a bit harder, I found a solution to pretty print a Bson instance. The trick is to convert it into an instance of BsonDocument, which has an implementation of the toString method that returns the string representation of the corresponding JSON.

    Bson bson = Filters.gt("a", 10);
    BsonDocument bsonDocument = bson.toBsonDocument(BsonDocument.class, MongoClient.DEFAULT_CODEC_REGISTRY);
    System.out.println(bsonDocument);
    

    The original link is the following: Converting Bson object to BsonDocument.

提交回复
热议问题