-
Book Overview & Buying
-
Table Of Contents
MongoDB Fundamentals
By :
When you work with MongoDB using database clients such as mongo shell, MongoDB Compass, or the Collections Browser in Mongo Atlas, you always see the documents in human readable JSON format. However, internally, MongoDB documents are stored in a binary format called BSON. BSON documents are not human-readable, and you will never have to deal with them directly. Before we explore MongoDB documents in detail, let's have a quick overview of the BSON features that benefit the MongoDB document structure.
Like JSON, BSON was introduced in 2009 by MongoDB. Although it was invented by MongoDB, many other systems also use it as a format for data storage or transportation. BSON specifications are primarily based on JSON as they inherit all the good features of JSON, such as the syntax and flexibility. It also provides a few additional features, which are specifically designed for improving storage efficiency, ease of traversal, and a few data type enhancements to avoid the type conflicts that we saw in the Introduction to JSON section.
As we have already covered the JSON features in detail, let's focus on the enhancements that BSON provides:
Note
Because of the binary format, BSON documents are compact in nature. However, some smaller documents end up occupying more space compared to JSON documents with the same information. This is because of the meta-information added to each document. However, for large documents, BSON is more space efficient.
Now that we have completed a detailed introduction to JSON and BSON enhancements, let's now learn about MongoDB documents.