# MongoDB - NOSQL Database

MongoDB is a **document-oriented NoSQL database** used for high-volume data storage. Instead of using tables and rows as in relational databases, MongoDB uses **collections and documents**.

### **Key Features of MongoDB**

1. **Schema-less** – No fixed structure, allowing flexibility.
2. **Scalability** – Horizontally scalable using **sharding**.
3. **High Performance** – Fast read and write operations.
4. **Replication** – Provides **high availability** using replica sets.
5. **Indexing** – Supports different types of indexes to improve query performance.
6. **Aggregation Framework** – Enables complex data transformations.

### **MongoDB Architecture**

MongoDB follows a **distributed architecture** with multiple components:

1. **Client** – Applications interact with MongoDB using drivers.
2. **MongoDB Server** – Stores and manages the data.
3. **Replica Set** – Ensures **fault tolerance** and high availability.
4. **Sharded Cluster** – Enables horizontal scaling for large datasets.
5. **Config Servers** – Store metadata for sharded clusters.
6. **Mongos Router** – Distributes queries across shards.

<figure><img src="/files/T1smgawzpG0HBcMpdLhx" alt=""><figcaption></figcaption></figure>

### **Basic MongoDB Operations**

**1. Creating a Database**

```javascript
use myDatabase;

```

2. Creating a Collection

```javascript
db.createCollection("users");

```

3. Inserting a Document

```javascript
db.users.insertOne({
    name: "John Doe",
    email: "john@example.com",
    age: 28,
    created_at: new Date()
});

```

4. Finding Documents

```javascript
db.users.find({ age: { $gt: 25 } });

```

5. Updating a Document

```javascript
db.users.updateOne(
    { email: "john@example.com" },
    { $set: { age: 30 } }
);

```

6. Deleting a Document

```javascript
db.users.deleteOne({ email: "john@example.com" });

```

### **MongoDB Use Cases**

* **Big Data Applications**
* **Real-time Analytics**
* **Internet of Things (IoT)**
* **Content Management Systems**
* **Mobile and Web Apps**


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.anandisheladiya.com/skills-and-experience/database/mongodb-nosql-database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
