Mongodb Select Pretty - MongoDB Tutorial



Mongodb Select Pretty

  • In mongoDB the data’s are displayed with the formatted alignment way using the pretty().
  • Configures the cursor to display results in an easy-to-read format.

Syntax :

db.collection.find(<query>).pretty() 
  • In mongoDB we quickly format the printing result sets with proper formatting in the mongo interactive shell using pretty() function.

Sample Query :

db.wikitechy4.find().pretty()
{ "_id" : ObjectId("5731e045daa4a0bc932a2ff8"), "name" : "data" }
{ "_id" : ObjectId("5731e258daa4a0bc932a2ff9"),
                          "websitename" : "www.wikitechy.com", 
                          "details" : "learn mongodb basics and step by step", 
                          "author" : "venkat" 
}
{ "_id" : ObjectId("5731e296daa4a0bc932a2ffa"), 
                         "websitename" : "www.wikitechy.com",
                         "details" : "learn mongodb basics and step by step",
                         "author”: "venkat" 
}
{ "_id" : ObjectId("5731e2eadaa4a0bc932a2ffb"), 
                         "websitename" : "www.wikitechy.com", 
                         "details" : "next row inserted", 
                         "articlecount" : "40", 
                         "author" : "jln" 
}
{ "_id" : ObjectId("5731e56ddaa4a0bc932a2ffc"), 
                             "websitename" : "www.wikitechy.com", 
                             "rowdetails" : "last row updated", 
                             "author" : "arun", 
                             "comments" : [ { 
                                                         "user" : "john", 
                                                          "message" : "article is good", 
                                                         "place" : "new york" 
                                                    } ]
 }
>

MongoDb


Output

MongoDb
  1. Here in this statement, we display the data in the collection “wikitechy4” using find().pretty() rich query in order to display the results in an easy-to-read format.


Related Searches to Mongodb Select Pretty - MongoDB Tutorial