Pretty print in MongoDB shell as default

537

Is there a way to tell Mongo to pretty print output? Currently, everything is output to a single line and it's difficult to read, especially with nested arrays and documents.

This question is tagged with mongodb command-line-interface mongo-shell

~ Asked on 2012-02-05 01:19:52

The Best Answer is


903

(note: this is answer to original version of the question, which did not have requirements for "default")

You can ask it to be pretty.

db.collection.find().pretty()

~ Answered on 2012-02-05 03:19:23


422

You can add

DBQuery.prototype._prettyShell = true

to your file in $HOME/.mongorc.js to enable pretty print globally by default.

~ Answered on 2012-07-09 14:47:02


Most Viewed Questions: