Definición
cursor.pretty()Importante
Método mongosh
Esta página documenta a Método
mongosh. Esta no es la documentación de un driver de lenguaje específico, como Node.js.Para los drivers de API de MongoDB, consulte la documentación del driver de MongoDB específica del 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()
Comportamiento
El método pretty():
No cambia el formato del resultado en
mongosh.Se modifica el formato de salida en el mongo shell heredado.
Ejemplos
Considera el siguiente 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 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" }