커서 객체의 Pretty() 함수를 호출하여 MongoDB 셸에서 prettyprint할 수 있습니다. 구문은 다음과 같습니다 -
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() 메서드를 사용하여 컬렉션의 모든 문서를 표시합니다. 쿼리는 다음과 같습니다 -
> 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"
]
}