2

Is there a way to set the indentation level of MongoDB's pretty shell command?

Sometimes, deeply nested objects need to be wrapped when pretty-printing. While modules such as Python's pprint have a setting for the indentation level, MongoDB's pretty API does not seem to provide this.

Is there a workaround (any way to set the indentation of pretty-printing)?

serv-inc
  • 35,772
  • 9
  • 166
  • 188

1 Answers1

3

As the mongo shell is a JavaScript shell, you can use its pretty-printing functionality. For example

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

The third parameter of JSON.stringify

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

serv-inc
  • 35,772
  • 9
  • 166
  • 188