Creating First Database and Collection in MongoDB
Creating First Database and Collection in MongoDB
1. Introduction to the Topic
In today’s fast-paced digital world, data plays a huge role in everything we do - from mobile apps to e-commerce to social media. Traditional databases like MySQL work well, but sometimes we need a more flexible and scalable option. That’s where MongoDB comes in.
MongoDB is a NoSQL database that stores data in the form of documents, making it highly adaptable and ideal for modern applications. In this blog, I will walk you through how I created my first database and collection using MongoDB as a beginner.
2. Explanation
Unlike traditional databases that use tables and rows, MongoDB uses collections and documents. Think of a collection like a folder, and a document like a file containing data in JSON format.
MongoDB does not require you to define a schema beforehand. You can just start adding data, and MongoDB will handle it flexibly. This makes it especially useful for projects that grow and change quickly.
A few key terms to know:
-
Database: Holds collections.
-
Collection: Holds documents (similar to a table).
-
Document: Actual data (in JSON format).
3. Procedure
Here are the steps I followed to create my first database and collection:
Step 1: Start MongoDB Server
Open the terminal and run:
This starts the MongoDB server on your machine.
Step 2: Open the Mongo Shell
In a new terminal tab or window, type:
This connects you to the MongoDB shell where you can start writing commands.
Step 3: Create a Database
To create a new database (for example: myFirstDatabase
), type:
Note: MongoDB creates the database only when you add data to it.
Step 4: Create a Collection
To create a new collection named students
, type:
Step 5: Insert a Document
Now insert your first document into the collection:
Step 6: View the Inserted Document
To see if the data was added, type:
This will display the document in a nicely formatted way.
4. Future Scope
MongoDB is widely used in modern technologies such as:
-
Web Development (with Node.js, Express.js, and React)
-
Big Data and Analytics
-
Internet of Things (IoT) Applications
-
Real-time Applications like chat apps or notification systems
-
Cloud-based Scalable Storage
As a BCA student, learning MongoDB opens doors to many career paths - especially in full-stack development, backend engineering, and data handling.
In future blogs, I plan to explore more MongoDB features like updating documents, deleting records, indexing, and aggregation pipelines.
Pruthviraj Sarjerao Patil
University: Sri Balaji University, Pune
School: School of Computer Studies
Course: BCA (Bachelor of Computer Applications)
Interests: SQL, NoSQL, MongoDB, and Related Technologies
Excellent work ππ»
ReplyDeleteExcellent π
ReplyDeleteExcellent Work ✌️
ReplyDeleteExcellent Work ππ»
ReplyDeleteGood
ReplyDeleteNicee
ReplyDeleteπnice
ReplyDeleteInformative and useful blog ππ»
ReplyDeleteGood
ReplyDeleteNice blogππ
ReplyDeleteHelpful and Excellent
ReplyDeleteInspiring blog
ReplyDeleteGood work π
ReplyDelete