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 ifPrettyPrinterappears not to be working, then try setting a smallermaxWidth.str := BsonIO.print(doc, 20)
maxWidthdefaults to80, andindentto 2 spaces.- readDoc
Str:Obj? readDoc(InStream in, TimeZone tz := TimeZone.cur())Reads a BSON document from an
InStream.Notes:
BINARYobjects with a subtype ofBIN_GENERICare returned as aBuf.CODEobjects are returned asStrs.INTEGER_32values are returned as 64-bitInts.REGEXflags are converted to embedded character flags.- Deprecated BSON objects are returned as
null.
All
DATEobjects 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 UTCbe 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
Bufis set to be little endian.