Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Cursors

cursor.pretty()

cursor.pretty()

Importante

Método mongosh

Este es un método mongosh. Esta no es la documentación de Node.js ni de otros métodos de controladores específicos de lenguajes de programación.

En la mayoría de los casos, los métodos mongosh funcionan de la misma manera que los métodos tradicionales mongo métodos shell. Sin embargo, algunos métodos heredados no están disponibles en mongosh.

Para la documentación heredada de mongo shell, revisa la documentación de la versión correspondiente de MongoDB Server:

Para los controladores de la API de MongoDB, consultar la documentación específica del controlador de MongoDB para cada lenguaje.

Configura el cursor para mostrar los resultados en un formato fácil de leer.

El método pretty() tiene la siguiente forma de prototipo:

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

El método pretty():

Considera el siguiente documento:

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

Por defecto, db.collection.find() devuelve datos en un 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" }

Al usar cursor.pretty() puedes configurar el cursor para que devuelva los datos en un formato más fácil de leer:

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

Volver

cursor.objsLeftInBatch

En esta página