mongodb - 在 mongo shell 中设置 pretty-print 的缩进级别

标签 mongodb pretty-print

有没有办法设置 MongoDB 的 pretty shell 命令的缩进级别?

有时,在 pretty-print 时需要包装深层嵌套的对象。而模块如 Python's pprint有一个缩进级别设置,MongoDB's pretty API似乎没有提供这个。

有没有解决方法(任何方法来设置 pretty-print 的缩进)?

最佳答案

the mongo shell是一个JavaScript shell,你可以use its pretty-printing functionality 。例如

JSON.stringify(db.runs.find()[0], null, 2)

JSON.stringify的第三个参数

indicates the number of space characters to use as white space;

关于mongodb - 在 mongo shell 中设置 pretty-print 的缩进级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45052363/

相关文章:

PHP SimpleXML 换行

json - 使用 jq 在 linux 命令行上打印大型 json 文件时出现问题

mongodb - IPTables 问题 : Can't connect to mongodb w/mongo shell - CentOS

vba - 如何漂亮地打印VBA代码?

node.js - 使用 Mongoose 保存身份验证凭据时出现问题

javascript - 当 Mongodb 未运行时,Mongoose.connect 不会抛出任何错误

python - 使用 lxml 将长 XML 标签拆分为多行

haskell - 在交互式 session 中在 haskell 中漂亮地垂直打印列表

node.js - Mongo shell 不显示内容

java - 蒙戈 : $type is not working in mongo find query