MongoDB\BSON classes

BSON stands for Binary JSON (http://bsonspec.org/). The MongoDB\BSON namespace consists of the following:

  • 6 functions: 6 functions, which perform conversions between BSON, JSON, and PHP native data types
  • 10 classes: 10 classes, which represent BSON data types (for example, Binary, Timestamp, and so on)
  • 13 interfaces: 13 interfaces, which are used to formulate custom classes which meet a certain criteria

In addition, three classes called DBPointer, Symbol, and Undefined are included but deprecated, and thus they are not discussed here.

In this example, we are using the MongoDB\BSON\Binary to store a binary image of a flag, extracted from a *.jpg file:

use MongoDB\BSON\Binary;use MongoDB\Driver\ {Manager, BulkWrite, ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.