Document
Mongodb stores data in the form of documents.
Documents are stored in memory as BSON.
Documents are represented as JSON for viewing and interaction.
BSON
Mongodb stores data internally and over the network in BSON.
BSON simply stands for “Binary JSON,” and that’s exactly what it was invented to be. BSON’s binary structure encodes type and length information, which allows it to be parsed much more quickly.
BSON bridges the gap between binary representation and JSON Format.
It is optimised for speed, space and flexibility.
THis allows to achieve high performance and general-purpose focus.
It also support non-native JSON data type such as Date and binary data using binary encoding, hence only providing machine readability.
Why data is stored in bson and not in json
This is due to some cons of json
JSON is a text-based format, and text parsing is very slow.
JSON’s readable format is far from space-efficient, another database concern.
JSON only supports a limited number of basic data types.
A comparsion between json and bson is here.
Last updated