
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Prettyprint in MongoDB shell as default?
You can call pretty() function on cursor object to prettyprint in MongoDB shell. The syntax is as follows −
db.yourCollectionName.find().pretty();
To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −
>db.prettyDemo.insertOne({"ClientName":"Larry","ClientAge":27,"ClientFavoriteCountry":["US","UK"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a440de01f572ca0ccf5f2") } >db.prettyDemo.insertOne({"ClientName":"Mike","ClientAge":57,"ClientFavoriteCountry":["AUS","UK"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a4420e01f572ca0ccf5f3") }
Display all documents from a collection with the help of find() method. The query is as follows −
> db.prettyDemo.find();
The following is the output −
{ "_id" : ObjectId("5c8a440de01f572ca0ccf5f2"), "ClientName" : "Larry", "ClientAge" : 27, "ClientFavoriteCountry" : [ "US", "UK" ] } { "_id" : ObjectId("5c8a4420e01f572ca0ccf5f3"), "ClientName" : "Mike", "ClientAge" : 57, "ClientFavoriteCountry" : [ "AUS", "UK" ] }
Here is the query to call pretty() function −
> db.prettyDemo.find().pretty();
The following is the output −
{ "_id" : ObjectId("5c8a440de01f572ca0ccf5f2"), "ClientName" : "Larry", "ClientAge" : 27, "ClientFavouriteCountry" : [ "US", "UK" ] } { "_id" : ObjectId("5c8a4420e01f572ca0ccf5f3"), "ClientName" : "Mike", "ClientAge" : 57, "ClientFavoriteCountry" : [ "AUS", "UK" ] }
- Related Articles
- Format date value in MongoDB shell?
- Does Mongo shell treats numbers as float by default.? How can we work it around explicitly?
- Use result from MongoDB in shell script?
- Inserting Date() in MongoDB through Mongo shell?
- Get output of MongoDB shell script?
- Variable collection name in MongoDB shell with JavaScript?
- How to print document value in MongoDB shell?
- How to unset a variable in MongoDB shell?
- How to define aliases in the MongoDB Shell?
- Which of the following elements has twice as many electrons in its second shell as in its first shell?
- Deleting all records of a collection in MongoDB Shell?
- How to terminate a MongoDB shell script earlier?
- How to run MongoDB shell using mongos command?\n
- Present date as default value in a table
- How to operate on all databases from the MongoDB shell?

Advertisements