Definição
cursor.pretty()Importante
Método mongosh
This page documents a
mongoshmethod. This is not the documentation for a language-specific driver, such as Node.js.Para drivers de API do MongoDB, consulte a documentação do driver do MongoDB específica da linguagem.
Configura o cursor para exibir os resultados em um formato fácil de ler.
The
pretty()method has the following prototype form:db.collection.find(<query>).pretty()
Comportamento
The pretty() method:
Does not change the output format in
mongosh.Altera o formato de saída no shell legado do mongo.
Exemplos
Considere o seguinte documento:
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"})
Por padrão, o db.collection.find() retorna dados em um formato denso:
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" }
By using cursor.pretty() you can set the cursor to return data in a format that is easier to read:
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" }