Pretty method in MongoDB for a prettier visualisation and an easy-to-read format

Pretty method in MongoDB

The pretty method gives us a prettier visualisation and form of the JSON result. It Configures the cursor to display results in an easy-to-read format.

Example of usage of pretty

db.articles.find().pretty();

Result with Pretty

{
        "_id" : ObjectId("5e2f4a6cf098cf25b5b434ca"),
        "name" : "something",
        "types" : [
                "type1",
                "type2"
        ],
        "nbr" : 52,
        "created_date" : ISODate("2017-10-10T00:00:00Z"),
        "metadata" : {
                "meta1" : "value1",
                "meta2" : "value2"
        }
}
{
        "_id" : ObjectId("5e2f4a6cf098cf25b5b434cb"),
        "name" : "something2",
        "types" : [
                "type1",
                "type2"
        ],
        "nbr" : 20,
        "other_field" : "field not on the other object",
        "created_date" : ISODate("2017-10-10T00:00:00Z"),
        "metadata" : {
                "meta5" : "value1",
                "meta6" : "value2"
        }
}

Result without Pretty

{ "_id" : ObjectId("5e2f4a6cf098cf25b5b434ca"), "name" : "something", "types" : [ "type1", "type2" ], "nbr" : 52, "created_date" : ISODate("2017-10-10T00:00:00Z"), "metadata" : { "meta1" : "value1", "meta2" : "value2" } }
{ "_id" : ObjectId("5e2f4a6cf098cf25b5b434cb"), "name" : "something2", "types" : [ "type1", "type2" ], "nbr" : 20, "other_field" : "field not on the other object", "created_date" : ISODate("2017-10-10T00:00:00Z"), "metadata" : { "meta5" : "value1", "meta6" : "value2" } }