Navigation

BSON

On this page

Overview

MongoDB stores data records as BSON documents. BSON is a binary representation of JSON documents, though it contains more data types than JSON. For the BSON spec, see bsonspec.org.

By default, the MongoDB PHP Library returns BSON documents as MongoDB\Model\BSONDocument objects and BSON arrays as MongoDB\Model\BSONArray objects, respectively.

Classes

MongoDB\Model\BSONArray

This class extends PHP’s ArrayObject class. It also implements PHP’s JsonSerializable interface and the driver’s MongoDB\BSON\Serializable and MongoDB\BSON\Unserializable interfaces.

By default, the library will deserialize BSON arrays as instances of this class. During BSON and JSON serialization, instances of this class will serialize as an array type (array_values() is used internally to numerically reindex the array).

MongoDB\Model\BSONDocument

This class extends PHP’s ArrayObject class. It also implements PHP’s JsonSerializable interface and the driver’s MongoDB\BSON\Serializable and MongoDB\BSON\Unserializable interfaces.

By default, the library will deserialize BSON documents as instances of this class. During BSON and JSON serialization, instances of this class will serialize as a document type (object casting is used internally).