BSON is a data format developed by 10gen, which is mainly used in MongoDB at present and is a data storage format of MongoDB. BSON is based on JSON format, and the main reason for choosing JSON for conversion is its universality and modeless.
BSON will mainly achieve the following three goals:
1. Faster traversal speed
For JSON format, too large JSON structure will lead to very slow data traversal. In JSON, if you want to skip a document for data reading, you need to scan the document and match troublesome data structures, such as parentheses. One of BSON's great improvements to JSON is that it stores the length of each element of JSON in the header of the element, so that you can read it directly at the specified point by reading the length of the element.
2. The operation is simpler
For JSON, data storage is untyped. For example, if you want to modify a basic value, from 9 to 10, because it has changed from one character to two, everything behind it may need to be moved back one place. Using BSON, this column can be designated as a number column, so whether the number is from 9 to 10 or 100, we only modify it where the number is stored, which will not increase the total data length. Of course, in MongoDB, if the number increases from integer to long integer, the total data length will still increase.
3. Other data types have been added.
JSON is a convenient data exchange format, but its types are limited. BSON adds the data type "byte array". This eliminates the need for base64 conversion of binary storage before it is saved as JSON. Greatly reduces the computational overhead and data volume.
Of course, sometimes BSON doesn't have the space advantage of JSON. For example, for {"field": 7}, JSON storage only uses one byte, but if BSON is used, it is at least 4 bytes (32 bits).
At present, with the efforts of 10gen, BSON already has codec packages in many languages. And they are all open source under the license of Apache 2. And it is still being further developed with MongoDB. About BSON,