使得 find 的输出在 shell 中可读
我们在收集测试中添加了三条记录:
> db.test.insert({"key":"value1","key2":"Val2","key3":"val3"})
WriteResult({ "nInserted" : 1 })
> db.test.insert({"key":"value2","key2":"Val21","key3":"val31"})
WriteResult({ "nInserted" : 1 })
> db.test.insert({"key":"value3","key2":"Val22","key3":"val33"})
WriteResult({ "nInserted" : 1 })
如果我们通过 find 看到它们,它们看起来会非常难看。
> db.test.find()
{ "_id" : ObjectId("5790c5cecae25b3d38c3c7ae"), "key" : "value1", "key2" : "Val2
", "key3" : "val3" }
{ "_id" : ObjectId("5790c5d9cae25b3d38c3c7af"), "key" : "value2", "key2" : "Val2
1", "key3" : "val31" }
{ "_id" : ObjectId("5790c5e9cae25b3d38c3c7b0"), "key" : "value3", "key2" : "Val2
2", "key3" : "val33" }
要解决此问题并使其可读,请使用 pretty ()函数。
> db.test.find().pretty()
{
"_id" : ObjectId("5790c5cecae25b3d38c3c7ae"),
"key" : "value1",
"key2" : "Val2",
"key3" : "val3"
}
{
"_id" : ObjectId("5790c5d9cae25b3d38c3c7af"),
"key" : "value2",
"key2" : "Val21",
"key3" : "val31"
}
{
"_id" : ObjectId("5790c5e9cae25b3d38c3c7b0"),
"key" : "value3",
"key2" : "Val22",
"key3" : "val33"
}
>