BSON()

Constructor

Create a new BSON instance

class BSON()
Returns:bson instance of BSON Parser.

Constants

Constant Name Value Description
BSON.BSON_DATA_NUMBER 1 Number BSON Type
BSON.BSON_DATA_STRING 2 String BSON Type
BSON.BSON_DATA_OBJECT 3 Object BSON Type
BSON.BSON_DATA_ARRAY 4 Array BSON Type
BSON.BSON_DATA_BINARY 5 Binary BSON Type
BSON.BSON_DATA_UNDEFINED 6 Binary BSON Type
BSON.BSON_DATA_OID 7 ObjectID BSON Type
BSON.BSON_DATA_BOOLEAN 8 Boolean BSON Type
BSON.BSON_DATA_DATE 9 Date BSON Type
BSON.BSON_DATA_NULL 10 null BSON Type
BSON.BSON_DATA_REGEXP 11 RegExp BSON Type
BSON.BSON_DATA_CODE 13 Code BSON Type
BSON.BSON_DATA_SYMBOL 14 Symbol BSON Type
BSON.BSON_DATA_CODE_W_SCOPE 15 Code with Scope BSON Type
BSON.BSON_DATA_INT 16 32 bit Integer BSON Type
BSON.BSON_DATA_TIMESTAMP 17 Timestamp BSON Type
BSON.BSON_DATA_LONG 18 Long BSON Type
BSON.BSON_DATA_MIN_KEY 0xff MinKey BSON Type
BSON.BSON_DATA_MAX_KEY 0x7f MaxKey BSON Type
BSON.BSON_BINARY_SUBTYPE_DEFAULT 0 Binary Default Type
BSON.BSON_BINARY_SUBTYPE_FUNCTION 1 Binary Function Type
BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY 2 Binary Byte Array Type
BSON.BSON_BINARY_SUBTYPE_UUID 3 Binary UUID Type
BSON.BSON_BINARY_SUBTYPE_MD5 4 Binary MD5 Type
BSON.BSON_BINARY_SUBTYPE_USER_DEFINED 128 Binary User Defined Type

BSON.calculateObjectSize

Calculate the bson size for a passed in Javascript object.

BSON.calculateObjectSize(object[, serializeFunctions])
Arguments:
  • object (object) – the Javascript object to calculate the BSON byte size for.
  • [serializeFunctions] (boolean) – serialize all functions in the object (default:false).
Returns:

number returns the number of bytes the BSON object will take up.

BSON.serializeWithBufferAndIndex

Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization.

BSON.serializeWithBufferAndIndex(object, checkKeys, buffer, index, serializeFunctions)
Arguments:
  • object (object) – the Javascript object to serialize.
  • checkKeys (boolean) – the serializer will check if keys are valid.
  • buffer (buffer) – the Buffer you pre-allocated to store the serialized BSON object.
  • index (number) – the index in the buffer where we wish to start serializing into.
  • serializeFunctions (boolean) – serialize the javascript functions (default:false).
Returns:

number returns the new write index in the Buffer.

BSON.serialize

Serialize a Javascript object.

BSON.serialize(object, checkKeys, asBuffer, serializeFunctions)
Arguments:
  • object (object) – the Javascript object to serialize.
  • checkKeys (boolean) – the serializer will check if keys are valid.
  • asBuffer (boolean) – return the serialized object as a Buffer object (ignore).
  • serializeFunctions (boolean) – serialize the javascript functions (default:false).
Returns:

buffer returns the Buffer object containing the serialized object.

BSON.deserializeStream

Deserialize stream data as BSON documents.

Options
  • evalFunctions {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
  • cacheFunctions {Boolean, default:false}, cache evaluated functions for reuse.
  • cacheFunctionsCrc32 {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
  • promoteLongs {Boolean, default:true}, when deserializing a Long will fit it into a Number if it’s smaller than 53 bits
BSON.deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex[, options])
Arguments:
  • data (buffer) – the buffer containing the serialized set of BSON documents.
  • startIndex (number) – the start index in the data Buffer where the deserialization is to start.
  • numberOfDocuments (number) – number of documents to deserialize.
  • documents (array) – an array where to store the deserialized documents.
  • docStartIndex (number) – the index in the documents array from where to start inserting documents.
  • [options] (object) – additional options used for the deserialization.
Returns:

number returns the next index in the buffer after deserialization x numbers of documents.

BSON.deserialize

Deserialize data as BSON.

Options
  • evalFunctions {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
  • cacheFunctions {Boolean, default:false}, cache evaluated functions for reuse.
  • cacheFunctionsCrc32 {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
  • promoteLongs {Boolean, default:true}, when deserializing a Long will fit it into a Number if it’s smaller than 53 bits
BSON.deserialize(buffer[, options][, isArray])
Arguments:
  • buffer (buffer) – the buffer containing the serialized set of BSON documents.
  • [options] (object) – additional options used for the deserialization.
  • [isArray] (boolean) – ignore used for recursive parsing.
Returns:

object returns the deserialized Javascript Object.

deserialize

Deserialize data as BSON.

Options
  • evalFunctions {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
  • cacheFunctions {Boolean, default:false}, cache evaluated functions for reuse.
  • cacheFunctionsCrc32 {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
deserialize(buffer[, options][, isArray])
Arguments:
  • buffer (buffer) – the buffer containing the serialized set of BSON documents.
  • [options] (object) – additional options used for the deserialization.
  • [isArray] (boolean) – ignore used for recursive parsing.
Returns:

object returns the deserialized Javascript Object.

deserializeStream

Deserialize stream data as BSON documents.

Options
  • evalFunctions {Boolean, default:false}, evaluate functions in the BSON document scoped to the object deserialized.
  • cacheFunctions {Boolean, default:false}, cache evaluated functions for reuse.
  • cacheFunctionsCrc32 {Boolean, default:false}, use a crc32 code for caching, otherwise use the string of the function.
deserializeStream(data, startIndex, numberOfDocuments, documents, docStartIndex[, options])
Arguments:
  • data (buffer) – the buffer containing the serialized set of BSON documents.
  • startIndex (number) – the start index in the data Buffer where the deserialization is to start.
  • numberOfDocuments (number) – number of documents to deserialize.
  • documents (array) – an array where to store the deserialized documents.
  • docStartIndex (number) – the index in the documents array from where to start inserting documents.
  • [options] (object) – additional options used for the deserialization.
Returns:

number returns the next index in the buffer after deserialization x numbers of documents.

serialize

Serialize a Javascript object.

serialize(object, checkKeys, asBuffer, serializeFunctions)
Arguments:
  • object (object) – the Javascript object to serialize.
  • checkKeys (boolean) – the serializer will check if keys are valid.
  • asBuffer (boolean) – return the serialized object as a Buffer object (ignore).
  • serializeFunctions (boolean) – serialize the javascript functions (default:false).
Returns:

buffer returns the Buffer object containing the serialized object.

calculateObjectSize

Calculate the bson size for a passed in Javascript object.

calculateObjectSize(object[, serializeFunctions])
Arguments:
  • object (object) – the Javascript object to calculate the BSON byte size for.
  • [serializeFunctions] (boolean) – serialize all functions in the object (default:false).
Returns:

number returns the number of bytes the BSON object will take up.

serializeWithBufferAndIndex

Serialize a Javascript object using a predefined Buffer and index into the buffer, useful when pre-allocating the space for serialization.

serializeWithBufferAndIndex(object, checkKeys, buffer, index, serializeFunctions)
Arguments:
  • object (object) – the Javascript object to serialize.
  • checkKeys (boolean) – the serializer will check if keys are valid.
  • buffer (buffer) – the Buffer you pre-allocated to store the serialized BSON object.
  • index (number) – the index in the buffer where we wish to start serializing into.
  • serializeFunctions (boolean) – serialize the javascript functions (default:false).
Returns:

number returns the new write index in the Buffer.

Contents

Manual

MongoDB Wiki