MongoDB\BSON\Persistable::bsonSerialize

Provides an array or document to serialize as BSON

&reftitle.description; abstract public ``array``stdClass``MongoDB\BSON\Document```MongoDB\BSON\Persistable::bsonSerialize`

Called during serialization of the object to BSON. The method must return an `array`, `stdClass`, or `MongoDB\BSON\Document`.

The return value will always be serialized as a BSON document. The serialized document will include a field containing the class name of the object. For this reason, it is not possible to return a `MongoDB\BSON\PackedArray` instance in this method.

Users are encouraged to include an `_id` property (e.g. a `MongoDB\BSON\ObjectId` initialized in your constructor) when returning data for a BSON root document; otherwise, the driver or database will need to generate a `MongoDB\BSON\ObjectId` when inserting or upserting the document, respectively.

&reftitle.parameters; &no.function.parameters;
&reftitle.returnvalues;

An `array`, `stdClass`, or `MongoDB\BSON\Document` to be serialized as a BSON document.

&reftitle.changelog;

&Version; | &Description;
PECL mongodb 1.17.0 | This method may now also return `MongoDB\BSON\Document` instances in addition to `array` and `stdClass`.

&reftitle.seealso;

- `MongoDB\BSON\Serializable::bsonSerialize`
- `MongoDB\BSON\Unserializable::bsonUnserialize`
- MongoDB\BSON\Persistable
- mongodb.persistence