cursor.pretty()
On this page
This version of the documentation is archived and no longer
supported. View the current documentation to learn how to
upgrade your version of MongoDB.
Definition
cursor.pretty()
Important
mongo Shell Method
This page documents the
mongo
shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.Configures the cursor to display results in an easy-to-read format.
The
pretty()
method has the following prototype form:db.collection.find(<query>).pretty()
Examples
Consider the following document:
db.books.save({ "_id" : ObjectId("54f612b6029b47909a90ce8d"), "title" : "A Tale of Two Cities", "text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...", "authorship" : "Charles Dickens"})
By default, db.collection.find()
returns data in a dense format:
db.books.find() { "_id" : ObjectId("54f612b6029b47909a90ce8d"), "title" : "A Tale of Two Cities", "text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...", "authorship" : "Charles Dickens" }
By using cursor.pretty()
you can set the cursor to return data in a
format that is easier for humans to parse:
db.books.find().pretty() { "_id" : ObjectId("54f612b6029b47909a90ce8d"), "title" : "A Tale of Two Cities", "text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...", "authorship" : "Charles Dickens" }