What is MongoDB?
Mongo DB is a NoSQL Database which is Not Only SQL Database.
It is an Open Source Database.
MongoDB is written primarily in C++
- The core database engine (storage, indexing, replication, performance-critical parts) is implemented in C++ for speed and efficiency.
MongoDB uses JavaScript as a scripting language, not as its foundation.
JavaScript is used for:
- The MongoDB Shell (mongosh)
- Writing queries, aggregation expressions

MongoDB is used in Full Stack Web Applications:
2 Popular stacks :
| MERN | MEAN |
| MongoDB | MongoDB |
| Express | Express |
| React | Angular |
| Node.js | Node.js |
NoSQL Databases :
Redis – Inmemory key value store
CouchDB
Cloud Firestore
MongoDB : Document Database
Relational Database :
Oracle
PostgreSQL
MySQL
NoSQL Databases : Document Based, Dynamic Schema, Horizontally Scalable, Not as good
Relational Databases : Table Based, Predefined Schema, Vertically Scalable, Good for complex queries.
| RDBMS | MongoDB |
| Database | Database |
| Tables | Collection |
| Rows | Documents |
| Columns | Fields |
| Table Join | Embedded Documents |
| Primary Key | Default_id provided by MongoDB |
MongoDB Structure :

- Database :
- A container for collections
- Has own set of files on system
- Can have multiple collections in single DB
- Collections :
- They are like tables in RDBMS
- They contain a set of records, normally of similar type
- Documents :
- Set of key value pairs
- Not required to have same set of fields.
- Fields can have different types of data.
- Default Port : 27017
Data types :
- String
- Integer
- Boolean
- Double
- Arrays
- TimeStamp
- Date
- Object (For embedded documents)
- Binary Data
- Plenty more
Single Document Inside Collection :
{ “_id” : ObjectId(“632njd8430924hdghgu394”), ß ObjectID which is Hexadecimal String
“email” : “info@infraxpertzz.com”, <- String
“status” : “For your daily IT Activities” <- String
“tags” : [ “Oracle”, “MySQL”, “MongoDB” ], <- Array of strings
“followers” : 10, <- Integer
“comments” : [{ <- These are embedded Documents
“username” : “abcd@gmail.com”,
“text” : “Provide more videos”,
“likes” : 5
“Number” : “123456789”
}
Unlike Relational Databases, you don’t need to create multiple tables to put details. Like if you need to add another phone number of an user in RDBMS, you need to add another table and then use primary or foreign keys. But in MongoDB, its not like that
“Number” : [ “123456789”, “789456123” ]
So, you can see from above, we have an array to 2 phone numbers.
| RDBMS | MongoDB |
| Select * from infra | db.infra.find() |
| Select * from infra where status = “Published” | db.infra.find( { status: “Published” } ) |
| select * from infra where status = “Published” or Topic = “MongoDB” | db.infra.find ( { $or: [ {status: “Published” } , { Topic : MongoDB } ] } ) |
MongoDB Data Format
JSON → JavaScript Object Notation
Data present in JSON is just a string
‘{
“type”: “phone”,
“price”: 120,
“features”: [
“HD Camera”,
“WiFi”
]
}’
Difference b/w JSON & JavaScript Object
| JSON | JavaScript Object |
| JSON is a string format | JavaScript Object is a variable type |
| Keys must be in double quotes | Keys need not be in quotes |
| Used for data storage & exchange | Used for data manipulation in JS |
| Cannot be used directly | Can be used directly in JavaScript |
Example Comparison
| JSON | JavaScript Object |
| ‘{ “type”: “Phone”, “price”: 120, “inStock”: true, “features”: [ “HD Camera”, “Wi‑Fi”, “LTE” ] }’ | { type: “Phone”, price: 120, inStock: true, features: [ “HD Camera”, “Wi‑Fi”, “LTE” ] } |
Conversion
| Operation | Description |
| JSON.parse() | Converts JSON → JavaScript Object |
| JSON.stringify() | Converts JavaScript Object → JSON |
JavaScript Object is a set of key‑value pairs surrounded by curly brackets.
It is not a string. It is an object in JavaScript.