Introduction to MongoDB bson

Source: Internet
Author: User
In the introduction of MongoDB's bson, BSON can be used as a storage form for network data exchange. This is a bit similar to Google's ProtocolBuffer, but BSON is a schema

In the introduction of MongoDB's bson, BSON can be used as a storage form for network data exchange. This is a bit similar to Google's Protocol Buffer, but BSON is a schema

1. What is bson?

BSON is a type of json Binary storage format, Binary JSON for short. Like JSON, BSON supports embedded document objects and array objects ,, however, BSON has some data types not available in JSON, such as Date and BinData.

BSON can be used as a storage mode for network data exchange. This is a bit similar to Google's Protocol Buffer, but BSON is a schema-less storage mode, which has the advantage of high flexibility, however, its disadvantage is that the space utilization is not ideal,

BSON has three features: lightweight, reproducible, and efficient.

{"Hello": "world"} This is a BSON example. "hello" is the key name, which is generally of the cstring type, and the byte value is cstring ::= (byte *) "/x00", where "*" indicates zero or multiple bytes, and "/x00" indicates the Terminator. "world" is the value. Its type is generally string, double, array, binarydata, and other types.

2. Use of bson in MongoDB

MongoDB uses the BSON structure to store data and exchange network data. Convert this format into a Document. Because BSON is schema-free, the Document corresponding to MongoDB also has this feature, A Document here can also be understood as a Record in a relational database, but the Document changes here are richer, such as the Document can be nested.

One of the important reasons why MongoDB uses BSON as its storage structure is its durability.

3. Several BSON examples 3.1 BSON representation of a Document:

This is a simple BSON struct. Each element is composed of key/value pairs.

3.2 nested example

This is an example of a relatively complex point, including an array of address objects and score objects. nested document objects and document object data are used to represent the information of a single student, this nested document structure is complicated to use relational databases.

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.