How do I enable mongodb cli pretty print? - db.col.find (). pretty () doesn't work

Using mongo v2.4.5 shell, db.col.find (). pretty () doesn't print much to me on the osx or linux ubuntu 12.04 bash console.

There is no diff in outputs with and without () character

> db.people.find() { "_id" : ObjectId("520d293752cfe6ece5d3fd77"), "name" : "Andrew" } { "_id" : ObjectId("520e448b77803f8f15fcfedb"), "name" : "Amy" } > > db.people.find().pretty() { "_id" : ObjectId("520d293752cfe6ece5d3fd77"), "name" : "Andrew" } { "_id" : ObjectId("520e448b77803f8f15fcfedb"), "name" : "Amy" } > 

What am I missing? (something crazy, no doubt)

thanks


UPDATE: doh! answered below. I did not understand that such a simple document would not be exaggerated. The attached documents are pretty good for me.

+4
source share
2 answers

.pretty will really make a difference when you have attached or larger documents:

 > db.so.insert( { name: "Derick" } ); > db.so.insert( { f: 'Derick', s: 'Rethans', t: 'derickr' } ); > db.so.insert( { name: { f: 'Derick', s: 'Rethans' } } ); > db.so.find(); { "_id" : ObjectId("520e49a21d7b77441eaf6446"), "name" : "Derick" } { "_id" : ObjectId("520e49b11d7b77441eaf6447"), "name" : { "f" : "Derick", "s" : "Rethans" } } > db.so.find().pretty(); { "_id" : ObjectId("520e49a21d7b77441eaf6446"), "name" : "Derick" } { "_id" : ObjectId("520e4f895a4563e39f06b030"), "f" : "Derick", "s" : "Rethans", "t" : "derickr" } { "_id" : ObjectId("520e49b11d7b77441eaf6447"), "name" : { "f" : "Derick", "s" : "Rethans" } } 

Therefore, I assume that it is great for you!

+10
source

You can add these lines to your file in $HOME/.mongorc.js to enable printing.

 DBQuery.prototype._prettyShell = true 

Alternatively, you can use this command, which prints documents in an array format:

 db.collection.find().toArray() 

Hooray!

+1
source

Source: https://habr.com/ru/post/1497462/


All Articles