Docs Menu
Docs Home
/
MongoDB マニュアル
/ / /

cursor.pretty()

項目一覧

  • 定義
  • 動作
cursor.pretty()

重要

mongosh メソッド

このページでは、 mongosh メソッドが文書化されます。これは Node.js などの言語固有のドライバーのドキュメントではありません

MongoDB API ドライバーについては、各言語の MongoDB ドライバー ドキュメントを参照してください。

読みやすい形式で結果を表示するようにカーソルを設定します。

pretty() メソッドのプロトタイプ形式は次のとおりです。

db.collection.find(<query>).pretty()

pretty() メソッドです。

  • mongosh の出力形式は変更されません。

  • レガシー mongo shell の出力形式を変更します。

次の文書をご覧ください。

db.books.save({
"_id" : ObjectId("54f612b6029b47909a90ce8d"),
"title" : "A Tale of Two Cities",
"text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...",
"authorship" : "Charles Dickens"})

デフォルトでは、db.collection.find() は高密度形式でデータを返します。

db.books.find()
{ "_id" : ObjectId("54f612b6029b47909a90ce8d"), "title" : "A Tale of Two Cities", "text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...", "authorship" : "Charles Dickens" }

cursor.pretty() を使用すると、カーソルがより読みやすい形式でデータを返すように設定できます。

db.books.find().pretty()
{
"_id" : ObjectId("54f612b6029b47909a90ce8d"),
"title" : "A Tale of Two Cities",
"text" : "It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness...",
"authorship" : "Charles Dickens"
}

戻る

cursor.objsLeftInBatch

項目一覧