classafBson::BsonIO
sys::Obj afBson::BsonIO
Reads and writes BSON documents to and from Streams and Bufs.
- print
Str print(Obj? val, Int? maxWidth := null, Str? indent := null)
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 ifPrettyPrinter
appears not to be working, then try setting a smallermaxWidth
.str := BsonIO.print(doc, 20)
maxWidth
defaults to80
, andindent
to 2 spaces.- readDoc
Str:Obj? readDoc(InStream in, TimeZone tz := TimeZone.cur())
Reads a BSON document from an
InStream
.Notes:
BINARY
objects with a subtype ofBIN_GENERIC
are returned as aBuf
.CODE
objects are returned asStrs
.INTEGER_32
values are returned as 64-bitInts
.REGEX
flags are converted to embedded character flags.- Deprecated BSON objects are returned as
null
.
All
DATE
objects are returned in the givenTimeZone
.This does not change the instant in the date time continuum, just time zone it is reported in. This lets a stored date time of
12 Dec 2012 18:00 UTC
be returned as12 Dec 2012 13:00 New_York
.- writeDoc
Buf writeDoc(Str:Obj? document, Buf? buf := null)
Writes the BSON document to a Buf.
As per BSON spec, the returned
Buf
is set to be little endian.