对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

游标()(mongosh方法)

cursor.pretty()

重要

mongosh 方法

本页介绍了mongosh 方法。这不是特定于语言的驾驶员(例如 Node.js)的文档。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

配置游标,以易于阅读的格式显示结果。

pretty()方法具有以下原型形式:

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

pretty()方法:

请考虑以下文档:

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

默认情况下,db.collection.find() 以密集格式返回数据:

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

通过使用cursor.pretty() ,可以将游标设立为以更易于阅读的格式返回数据:

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"
}
给本页内容打分

在此页面上