# What is MongoDB?
*MongoDB is a NoSQL database that stores data in flexible, JSON-like documents.*
By [Rohit Lakhotia](https://scaleengineer.com/authors/rohit-lakhotia)
Published: 2024-07-01
Canonical: https://scaleengineer.com/blog/what-is-mongodb
---
Have you ever needed a database that can effortlessly handle large volumes of diverse data, without being constrained by rigid schemas? **MongoDB **might just be the answer you're looking for\. Let’s discuss more about MongoDB in this blog today\.

### History of MongoDB

MongoDB was launched in **2009 **by **10gen \(now MongoDB Inc\.\)**, addressing limitations of traditional relational databases with its document\-oriented, **JSON\-based storage\.** It quickly gained popularity for its scalability, speed, and flexibility, becoming a leading NoSQL database solution\.

### What is MongoDB?

MongoDB is an open\-source, document\-oriented [NoSQL](/glossaries/nosql) database designed to handle large amounts of data and provide fast performance\.

**In simple terms,**

MongoDB is a type of database that doesn't use tables like traditional databases do\. Instead, it stores data in a way that's similar to how you'd organize information in **JSON** files\.

This makes it easy to handle data that doesn't have a fixed structure\. MongoDB can quickly find information because it indexes everything, and it can copy data across different machines automatically\. Plus, it has easy\-to\-use tools for working with your data\.

Below is an example of a JSON\-like document in a MongoDB database:

```
{
  "company_name": "Glich Technologies",
  "address": {
       "street": "1522 MG Road", 
       "city": "Bangalore"
   },
  "phone_number": 1234567890,
  "industry": ["education", "technology"]
  "type": "private",
  "number_of_employees": 1200
}
```

### Elements of MongoDB

For example, let's consider a database named "**Glich Technologies**"\. This database contains two collections, and within these collections, there are two documents\. These documents store data in the form of fields, as illustrated below:

![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/c996416f-63b7-4c39-820e-32ca898e52d6/image.png?t=1718968022)

- **Document**: A single unit of data in MongoDB, similar to a row in a SQL table\.
- **Field**: A key\-value pair within a document that stores a specific piece of data\.
- **Collection**: A grouping of MongoDB documents, similar to a table in a SQL database\.
- **Database**: A container for collections in MongoDB, similar to a database in a SQL system\.
- **Schema**: Defines the structure of documents in MongoDB\. Unlike SQL databases, MongoDB does not require predefined schemas for collections\.
- **Index**: A data structure that improves the speed of data retrieval in MongoDB, similar to indexes in [SQL](/glossaries/structured-query-language) databases\.
- **Primary Key**: A unique identifier for each document in a MongoDB collection, automatically created and indexed by MongoDB\.
- **Denormalization**: Storing duplicated data within documents to improve query performance, contrary to the normalization process in SQL databases\.
- **Joins**: A method to combine data from multiple collections or documents in MongoDB, introduced in MongoDB version 3\.6 with some limitations\.
- **Transactions**: Atomic operations that ensure either all or none of the updates to a single document succeed in MongoDB, extended to multi\-document transactions in MongoDB version 4\.0\.

### CRUD operations in MongoDB

**Creating and Inserting Documents**: To add a new document, define its structure using JSON\-like objects\. For instance, to create a user document with name, email, and age:

```
{ "name": "John Smith", "email": "john.smith@example.com", "age": 32 }
```

Insert it into MongoDB using insertOne\(\):

```
db.users.insertOne({ "name": "John Smith", "email": "john.smith@example.com", "age": 32 });
```

**Reading Documents**: Retrieve documents with find\(\)\. To get all users:

```
db.users.find();
```

To filter by age greater than 30:

```
db.users.find({ "age": { $gt: 30 } });
```

**Updating Documents**: Modify a document with updateOne\(\)\. Update John Smith's email:

```
db.users.updateOne( { "name": "John Smith" }, { $set: { "email": "new.email@example.com" } } );
```

**Deleting Documents**: Remove a document using deleteOne\(\)\. Delete John Smith's entry:

```
db.users.deleteOne({ "name": "John Smith" });
```

### What Is MongoDB Used For?

- **Document\-Oriented**: Stores data in JSON format, allowing flexible and fast retrieval\.
- **Flexible Querying**: MongoDB supports dynamic queries by fields within documents, including regular expressions and range queries\. This makes it easy to find specific data as needed\.
- **High Speed**: Known for its fast performance, even with massive datasets\.
- **Flexible Indexing**: Any field within a document can be indexed to enhance search performance, providing additional flexibility in data access\.
- **Language Agnostic**: It offers drivers for various programming languages like Node\.js, Python, Java, and more\. This versatility allows MongoDB to integrate seamlessly with different application environments\.
- **Sharding**: MongoDB can** ****[horizontally scale](/blog/vertical-vs-horizontal-scaling)** by distributing data across multiple servers using a technique called **sharding**\. This ensures high availability and performance by spreading data load efficiently\.

### Benefits of MongoDB:

- Handles diverse types of data **\(structured, semi\-structured, unstructured\)**
- Supports **high availability, scalability, **and real\-time analytics

### Use Cases:

- Real\-time analytics and processing of large datasets
- Content management systems requiring flexible data storage **\(text, images, video\)**

### Companies using MongoDB

eBay, Shutterfly, Confidential Records Inc, Toyota, Paylocity, Verizon, TIM, Marsello, MetLife, Cisco, Zendesk Inc, Brookings Institution, Forbes, Sanoma, Conrad, Helvetia, Intuit, FEMA,etc\.

### Disadvantages of MongoDB

- **ACID Support**: No full ACID support **\(atomicity, consistency, isolation, durability\)**
- **Standardization**: Lack of standardized practices compared to relational databases\.
- **Scale\-out Performance**: MongoDB has **scale\-out \(horizontal scaling\)** abilities via its** replica sets**, but the scale\-out performance may be limited compared to what relational databases platforms can produce\. 

### How MongoDB is different from RDBMS?

| **MongoDB** | **RDBMS** |
| --- | --- |
| It is a non\-relational and document\-oriented database\. | It is a relational database\. |
| It is suitable for hierarchical data storage\. | It is not suitable for hierarchical data storage\. |
| It has a dynamic schema\. | It has a predefined schema\. |
| It centers around the CAP theorem \(Consistency, Availability, and Partition tolerance\)\. | **I**t centers around ACID properties \(Atomicity, Consistency, Isolation, and Durability\)\. |
| In terms of performance, it is much faster than RDBMS\. | In terms of performance, it is slower than MongoDB\. |

By now, you must have had a clear idea of **MongoDB**, from its meaning to working you know all of it now\. In a nutshell,** MongoDB is a flexible, scalable, and high\-performance NoSQL database that stores data in JSON\-like documents, making it ideal for modern web applications\.** So, as you navigate through the vast expanse of the internet, stay informed, stay secure, and embrace the adventure of the digital realm\!

**Congratulations\! You've just advanced another step in your tech journey\. Keep progressing\!**
