定義
cursor.pretty()重要
mongosh メソッド
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。
読みやすい形式で結果を表示するようにカーソルを設定します。
The
pretty()method has the following prototype form:db.collection.find(<query>).pretty()
動作
pretty()メソッド:
レガシー Mongo shell の出力形式を変更します。
例
次の文書をご覧ください。
db.books.insertOne({ "_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" }