Bson is currently mainly used in MongoDB, is the data storage format of MongoDB, Bson based on JSON format, the main reason to choose JSON for transformation is the universality of JSON and the characteristics of JSON schemaless.
Bson mainly achieve the following three points:
1. Faster Traverse speed
in JSON format, too large a JSON structure can cause data traversal to be very slow. In JSON, to skip a document for data reading, this document needs to be scanned before it can be done, requiring cumbersome data structure matching, such as the matching of parentheses.
A big improvement to JSON, however, is that it bson the length of each element of the JSON to the head of the element, so that you simply need to read the length of the element to read directly to the specified point.
2, easy to operate
for JSON, data storage is untyped, for example, if you want to modify a basic value, from 9 to 10, since a character becomes two, everything behind it may need to be moved backwards.
Using Bson, you can specify this column as a number, then whether the number from 9 to 10 or 100, we are only stored in the number of the one on the change, does not cause the total length of the data to become larger.
Of course, in MongoDB, if the number is increased from shaping to a long integer, it will cause the total length of the data to grow larger.
3. Added additional data types
JSON is a convenient format for data interchange, but its type is relatively limited.
The Bson adds a "byte array" data type based on it. This allows binary storage to be Base64 converted and then saved into JSON, greatly reducing the computational overhead and data size.
Sum up
JSON is stored as a string in the data structure, and Bson is stored by structure.
Storage space on Bson>json
Operating speed on the Bson>json. For example, traversal lookup: JSON needs to sweep a string, and Bson can directly position it directly with the string length that precedes the string.
Modify the JSON to change because of the length of the string to move large, bson words because it is stored by the structure, so still occupy the same storage space, do not need to move.
The difference between Bson and JSON