Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty print in MongoDB shell as default

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.

like image 307
raffian Avatar asked Feb 05 '12 01:02

raffian


People also ask

What does pretty () do in MongoDB?

The pretty() method: Does not change the output format in mongosh . Changes the output format in the legacy mongo shell.

What does .save do in MongoDB?

MongoDB's update() and save() methods are used to update document into a collection. The update() method updates the values in the existing document while the save() method replaces the existing document with the document passed in save() method.

What is MongoDB shell Mongosh?

The MongoDB Shell, mongosh , is a fully functional JavaScript and Node. js 16. x REPL environment for interacting with MongoDB deployments. You can use the MongoDB Shell to test queries and operations directly with your database. mongosh is available as a standalone package in the MongoDB download center.

What is Upsert MongoDB?

In MongoDB, upsert is an option that is used for update operation e.g. update(), findAndModify(), etc. Or in other words, upsert is a combination of update and insert (update + insert = upsert).


1 Answers

(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() 
like image 131
Sergio Tulentsev Avatar answered Oct 02 '22 01:10

Sergio Tulentsev