Bson differs from JSON __json

Source: Internet
Author: User
Tags mongodb

Bson is a data format developed by 10gen, currently mainly used in MongoDB, is the MONGODB data storage format. Bson based on the JSON format, the main reason for choosing JSON for transformation is the versatility of JSON and the schemaless characteristics of JSON.

Bson will mainly achieve the following three goals: 1. Faster traversal speed

For the JSON format, too large a JSON structure can cause data traversal to be very slow. In JSON, to skip a document for data reading, you need to scan the document for a troublesome data structure match, such as a brace match, and Bson's big improvement to JSON is that it will have the element's head in the length of each element of JSON, This way you only need to read the length of the element to direct seek to the specified point for reading. 2. More simple Operation

For JSON, the data store is untyped, such as if you want to modify a basic value, from 9 to 10, because from one character to two, all the content behind it may need to be moved backwards. And using Bson, you can specify this column as a number, so regardless of whether the number from 9 to 10 or 100, we are only in the number of the store to modify, does not cause the total data grow larger. Of course, in MongoDB, if the number is increased from the shape to the long integer, it will still cause the total length of the data to become larger. 3. Additional data types are added

JSON is a convenient format for data interchange, but its type is relatively limited. Bson adds a "byte array" data type on its basis. This makes binary storage no longer needed to base64 the conversion before saving it as JSON. Greatly reduces the computational overhead and data size.

Of course, in some cases, Bson has no space advantage over JSON, for example, to {"Field": 7}, 7 uses only one byte in JSON storage, and if you use Bson, that's at least 4 bytes (32 bits).

At present, with the effort of 10gen, Bson has a codec pack for multiple languages. And all are Apache 2 license under the open source. And it is further developed with MongoDB. About Bson,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.