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.