
What is MongoDB, Introduction and the Technology It Uses

Photo By Unsplash on Unsplash
In the previous article, we discussed NoSQL databases and their types. I want to refresh your memory about NoSQL databases with a document model. In short, this database model is represented in the form of document objects written in JSON format.
MongoDB is related to this concept because it follows the Document database model. MongoDB itself is developed using the C++ programming language.
If you are accustomed to SQL databases with relational tables, you might find it a bit challenging to adapt to MongoDB. I personally experienced the same difficulty and needed some time to get used to working with a document model database.
Additionally, I find relational databases to be more structured when setting rules and criteria. You just need to pay attention to database normalization to avoid data redundancy (data duplication).
However, every technology has its own advantages and disadvantages. SQL/relational databases tend to be rigid and less flexible. In contrast, document-based databases provide high flexibility in data management because data storage and manipulation occur within objects.
The image below serves as a reminder of our previous discussion on document databases and the flexibility of data management within an object.

Example of writing a document object in JSON format.
Documents and Collections in MongoDB
To better understand documents and collections in MongoDB, let’s use an analogy. Since MongoDB uses a document model, a collection of multiple documents in the same file can be compared to a table in an SQL/relational database.
Meanwhile, an individual document can be considered a record. Properties within an object function like columns, and each property has its respective value.

JSON is a representation of the document model database, so we need to discuss how data is written in JSON format. You can also visit the link below to read JSON documentation directly.
Why is it called JSON? Is JSON the same as JavaScript?
Let’s answer these questions one by one. It is called JSON because its writing format adopts the object notation style from JavaScript, hence the name “JavaScript Object Notation.” If you are familiar with JavaScript objects, understanding JSON should be easy.
For the second question, JSON is not part of JavaScript. JSON is an independent data format that can stand alone. It serves as a bridge between various programming languages since almost all modern programming languages support JSON format.
1. Object Structure
It is written by starting with an opening curly brace and ending with a closing curly brace, where each value is bound by a property/attribute, and each object or property is separated by a comma (,).

For those of you who are still confused, you can refer to the following code snippet.
[{ "nama" : "iqbal", "umur" : 23 }, { "nama" : "niyaz", "umur" : 2 }]
2. Array Structure
Just like writing arrays in general, which start with an opening square bracket [ and end with a closing square bracket ]. In my opinion, arrays are a great way to manage data. Hopefully, in the future, I can write a dedicated tutorial on this topic. For a visual representation, refer to the image below.

Values in an array can be objects because, in my habit of developing applications with the JSON format, I usually store data in an array.
Meanwhile, the values in JSON can be objects, arrays, numbers, strings, booleans, or null. Objects and arrays can also be nested objects or nested arrays.

Documents stored on disk (HDD, SSD, or server) are written in BSON (Binary JSON) format. If you are unfamiliar with BSON, you can visit the following link for more information.
BSON is a lightweight binary format compared to other binary formats. Its lightweight nature makes it crucial for data transformation on the web.
Additionally, BSON has a Traversal characteristic (easy to navigate), and lastly, it has an Efficient characteristic, making it perform very fast and easy to navigate when encoding and decoding data.
Here are some types of data represented in the BSON format :
- UTF-8 String
- 32-bit Integer (int32)
- 64-bit Integer (int64)
- Floating Point (double)
- Document (object)
- Array (array)
- Binary Data (binary)
- Boolean (true/false)
- Null
- Regular Expression
- JavaScript Code
- JavaScript Code with Scope
- ObjectId
From the explanation above, we can conclude why learning MongoDB is essential for building modern applications:
- MongoDB follows the document database model, making data management more flexible according to application needs.
- MongoDB uses JSON format, which is supported by almost all modern programming languages.
- MongoDB stores data in BSON (Binary JSON) format, which is lightweight, traversable, and efficient.
That’s the explanation of What is MongoDB, Introduction and the Technology It Uses that Mangcoding can share. Hopefully, this article is useful and provides new insights for you. If you have constructive feedback or suggestions, feel free to leave a comment or contact us via email and Mangcoding’s social media.
Source : Medium.com