Definición
cursor.pretty()Importante
Método mongosh
Este es un método.
mongoshEsta no es la documentación deNode.jsni de otros métodos de controlador específicos del lenguaje de programación.En la mayoría de los casos, los métodos funcionan de la misma manera que los
mongoshheredados.mongoMétodos de shell. Sin embargo, algunos métodos heredados no están disponiblesmongoshen.Para obtener la documentación del shell heredado, consulte la documentación de la versión correspondiente de MongoDB
mongoServer: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 tiene la siguiente forma de
pretty()prototipo:db.collection.find(<query>).pretty()
Comportamiento
El pretty() método:
No cambia el formato de salida
mongoshen.Cambia el formato de salida en el shell mongo heredado.
Ejemplos
Considere 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"})
De forma predeterminada, devuelve datos en un formatodb.collection.find() 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 utilizar puede configurar el cursor para que devuelva datos en un formato que sea más fácil de cursor.pretty() 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" }