logo
Published on

MongoDB Tutorial 2025

Authors
  • avatar
    Name
    Ganesh Negi
    Twitter

What is MongoDB ?

MongoDB is a database server where we can create a huge database.

Mongo means huge means it can store a lot of data efficienlty.

MySQL have schema whereas in mongodb it is a schemaless

MySQL have database -> Table -> rows whereas in Mongodb it has Database -> Collection -> Documents

Documents basically save in JSON format


Here, it is a employee collection have data saved as a documents

{
    "name" : "Ganesh",
    "age": 32,
    "city": "Noida",
    "identity" : {
        "aadhar" : 873897398478954,
        "pan": "PODJD8797K"
    }
}

identity is a another docuement hence, we can save nested documents here.

Another example, here another new data has been added according to employee experience , as in above example where employee is fresher
that's why it is schemaless


{
    "name" : "Bhavesh",
    "age": 40,
    "city": "Delhi",
    "identity" : {
        "aadhar" : 873897398478954,
        "pan": "PODJD8797K"
    },
    "previous: : {
        "N2R Tech",
        "IUS Tech"
    }
}

due to schemaless feature its increase flexibility, scalability .

Summary:-

  • mongodb is less relations.
  • data is stored together.

What is BSON ?

"Binary JSON"

BSON's binary structure encodes type and length information, which allows it to be traversed much more quickly compared to JSON.

How to create database in MongoDB ?

- go to mongo shell
- use tutorial_mongodb (It will create database if not exists)
- db.students.insertOne({name: "Ganesh", age: 12})  (this command is for insert data into students collections)
- db.students.find() (this will show all data in students collection)

Aggregation in MongoDB

here, _id is a unique identifier for each document in a students collection.

vijyle.

Embedded documents in MOngoDB (Nested documents limit)