默认情况下,MongoDB Shell中的Prettyprint吗?
您可以pretty()
在MongoDBShell中调用游标对象上的function进行漂亮打印。语法如下-
db.yourCollectionName.find().pretty();
为了理解这个概念,让我们用文档创建一个集合。使用文档创建集合的查询如下-
>db.prettyDemo.insertOne({"ClientName":"Larry","ClientAge":27,"ClientFavoriteCountry":["US","UK"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a440de01f572ca0ccf5f2") } >db.prettyDemo.insertOne({"ClientName":"Mike","ClientAge":57,"ClientFavoriteCountry":["AUS","UK"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8a4420e01f572ca0ccf5f3") }
在find()
method的帮助下显示集合中的所有文档。查询如下-
> db.prettyDemo.find();
以下是输出-
{ "_id" : ObjectId("5c8a440de01f572ca0ccf5f2"), "ClientName" : "Larry", "ClientAge" : 27, "ClientFavoriteCountry" : [ "US", "UK" ] } { "_id" : ObjectId("5c8a4420e01f572ca0ccf5f3"), "ClientName" : "Mike", "ClientAge" : 57, "ClientFavoriteCountry" : [ "AUS", "UK" ] }
这是调用pretty()
函数的查询-
> db.prettyDemo.find().pretty();
以下是输出-
{ "_id" : ObjectId("5c8a440de01f572ca0ccf5f2"), "ClientName" : "Larry", "ClientAge" : 27, "ClientFavouriteCountry" : [ "US", "UK" ] } { "_id" : ObjectId("5c8a4420e01f572ca0ccf5f3"), "ClientName" : "Mike", "ClientAge" : 57, "ClientFavoriteCountry" : [ "AUS", "UK" ] }