const classafMongo::PrettyPrinter

sys::Obj
  afMongo::PrettyPrinter

Pretty prints MongoDB documents to a JSON-esque string. Useful for debugging.

Note PrettyPrinter only pretty prints if the resulting text string if greater than maxWidth. So if PrettyPrinter appears not to be working, then try setting a smaller maxWidth.

str := PrettyPrinter { maxWidth=20 }.print(mongoDoc)
convertHook

Source

virtual Obj? convertHook(Obj? val)

A simple override hook to alter values before they are printed.

By default this just returns the given value.

indent

Source

const Str indent := " "

The indent string used to indent the document.

make

Source

new make(|This? f := null)

Creates a PrettyPrinter with the default pretty printing options. May be either a PrettyPrintOptions instance, or just false to disable pretty printing.

printer := PrettyPrinter()
printer := PrettyPrinter { it.indent="\t"; it.maxWidth=40; }
maxWidth

Source

const Int maxWidth := 80

The maximum width of a list or map before it is broken up into separate lines.

prettyPrint

Source

const Bool prettyPrint := true

Set to false to disable pretty printing and have documents printed on a single line.

print

Source

Str print(Obj? obj)

Pretty prints the given MongoDB object / document to a Str.

str := prettyPrinter.print(mongoDoc)
printToStream

Source

This printToStream(Obj? obj, OutStream out)

Pretty prints the given MongoDB object / document to a stream.

prettyPrinter.print(mongoDoc, out)