On this page:
int32?
int64?
bson-document/ c
bson-sequence/ c
bson-min-key?
bson-min-key
bson-max-key?
bson-max-key
bson-null?
bson-null
bson-timestamp
bson-objectid?
new-bson-objectid
bson-objectid-timestamp
bson-javascript
bson-javascript/ scope
bson-binary
bson-regexp
2.1 Decoding Conventions

2 BSON

 (require (planet jaymccarthy/mongodb:1:0/bson/main))

MongoDB depends on BSON. This module contains an encoding of BSON values as Scheme values.

A BSON document is a dictionary that maps symbols to BSON values.

A BSON value is either

A BSON sequence is sequence of BSON values.

(int32? x)  boolean?
  x : any/c
A test for 32-bit integers.
(int64? x)  boolean?
  x : any/c
A test for 64-bit integers.
bson-document/c : contract?
A contract for BSON documents.
bson-sequence/c : contract?
A contract for BSON sequences.

A few BSON types do not have equivalents in Scheme.

(bson-min-key? x)  boolean?
  x : any/c
A test for bson-min-key.
bson-min-key : bson-min-key?
The smallest BSON value.
(bson-max-key? x)  boolean?
  x : any/c
A test for bson-max-key.
bson-max-key : bson-max-key?
The largest BSON value.
(bson-null? x)  boolean?
  x : any/c
A test for bson-null.
bson-null : bson-null?
The missing BSON value.
(struct bson-timestamp (value)
  #:extra-constructor-name make-bson-timestamp)
  value : int64?
A value representing an internal MongoDB type.
(bson-objectid? x)  boolean?
  x : any/c
A test for BSON ObjectIds, an internal MongoDB type.
(new-bson-objectid)  bson-objectid?
Returns a fresh ObjectId.
(bson-objectid-timestamp oid)  exact-integer?
  oid : bson-objectid?
Returns the part of the ObjectID conventionally representing a timestamp.

A few BSON types have equivalents in Scheme, but because of additional tagging of them in BSON, we have to create structures to preserve the tagging.

(struct bson-javascript (string)
  #:extra-constructor-name make-bson-javascript)
  string : string?
A value representing Javascript code.
(struct bson-javascript/scope (string scope)
  #:extra-constructor-name make-bson-javascript/scope)
  string : string?
  scope : bson-document/c
A value representing Javascript code and its scope.
(struct bson-binary (type bs)
  #:extra-constructor-name make-bson-binary)
  type : (symbols 'function 'binary 'uuid 'md5 'user-defined)
  bs : bytes?
A value representing binary data.
(struct bson-regexp (pattern options)
  #:extra-constructor-name make-bson-regexp)
  pattern : string?
  options : string?
A value representing a regular expression.

2.1 Decoding Conventions

Only make-hasheq dictionaries are returned as BSON documents.

A bson-binary? where bson-binary-type is equal to 'binary is never returned. It is converted to bytes?.

Only vector sequences are returned as BSON sequences.