> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# BSON

## 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](https://bsonspec.org/).

By default, the MongoDB PHP Library returns BSON documents as [`MongoDB\Model\BSONDocument`](https://www.mongodb.com/docs/php-library/current/reference/bson.md#mongodb-phpclass-phpclass.MongoDB-Model-BSONDocument) objects and BSON arrays as [`MongoDB\Model\BSONArray`](https://www.mongodb.com/docs/php-library/current/reference/bson.md#mongodb-phpclass-phpclass.MongoDB-Model-BSONArray) objects, respectively.

## Classes

This class extends PHP's [ArrayObject](https://php.net/arrayobject) class. It also implements PHP's [JsonSerializable](https://php.net/jsonserializable) interface and the extension's [MongoDB\BSON\Serializable](https://php.net/mongodb-bson-serializable) and [MongoDB\BSON\Unserializable](https://php.net/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()](https://php.net/array_values) is used internally to numerically reindex the array).

This class extends PHP's [ArrayObject](https://php.net/arrayobject) class. It also implements PHP's [JsonSerializable](https://php.net/jsonserializable) interface and the extension's [MongoDB\BSON\Serializable](https://php.net/mongodb-bson-serializable) and [MongoDB\BSON\Unserializable](https://php.net/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](https://php.net/types.type-juggling#language.types.typecasting) is used internally).
