how do I enable mongodb cli pretty print? - db.col.find().pretty() not working
mongodb
Solution
`.pretty` will only really change things when you have nested 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"
}
}
So I presume it works just fine for you!
Problem
Using mongo v2.4.5 shell, db.col.find().pretty() does not pretty print for me on either osx console or linux ubuntu 12.04 bash. There is no diff in the output with and without pretty() ``` > 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 basic no doubt) Thx UPDATE: doh! answered below. I had not realized such a simple doc would not be prettified. Nested docs pretty fine for me.