如何启用 mongodb cli 漂亮打印?- db.col.find().pretty() 不工作 [英] how do I enable mongodb cli pretty print? - db.col.find().pretty() not working

查看:49
本文介绍了如何启用 mongodb cli 漂亮打印?- db.col.find().pretty() 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 mongo v2.4.5 shell,db.col.find().pretty() 在 osx 控制台或 linux ubuntu 12.04 bash 上对我来说打印效果不佳.

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.

有和没有pretty()的输出没有差异

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)

谢谢

更新:哦!下面回答.我没有意识到这样一个简单的文档不会被美化.嵌套文档对我来说非常好.

UPDATE: doh! answered below. I had not realized such a simple doc would not be prettified. Nested docs pretty fine for me.

推荐答案

.pretty 只有当你有嵌套或更大的文档时才会真正改变:

.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"
    }
}

所以我认为它适合你!

这篇关于如何启用 mongodb cli 漂亮打印?- db.col.find().pretty() 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆