Menu Docs

Página inicial do DocsDesenvolver aplicaçõesManual do MongoDB

cursor.pretty()

Nesta página

  • Definição
  • Comportamento
  • Exemplos
cursor.pretty()

Importante

Método mongosh

Esta página documenta um método mongosh . Esta não é a documentação para um driver específico de idioma, como Node.js.

Para drivers de API do MongoDB, consulte a documentação do driver MongoDB específica do idioma.

Configura o cursor para exibir os resultados em um formato fácil de ler.

O método pretty() tem a seguinte forma de protótipo:

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

O método pretty() :

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" }

Ao usar cursor.pretty() , você pode definir o cursor para retornar dados em um formato mais fácil de ler:

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()