在 mongo shell 中设置漂亮打印的缩进级别

Set indentation level for pretty-printing in mongo shell

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

有时候,嵌套很深的对象在漂亮打印的时候需要包裹起来。虽然 Python's pprint have a setting for the indentation level, MongoDB's pretty API 等模块似乎没有提供此功能。

是否有解决方法(任何设置漂亮打印缩进的方法)?

the mongo shell is a JavaScript shell, you can 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;