MongoDB Tutorial
MongoDB is a popular NoSQL database. Instead of tables with fixed columns, it stores data as flexible documents that look like JSON.
MongoDB is the "M" in the MERN stack (MongoDB, Express, React, Node.js), one of the most common stacks for full-stack JavaScript jobs and freelance projects.
Why Learn MongoDB?
- Documents look like JavaScript objects, so it feels natural for JavaScript developers
- Different documents in one collection can have different fields
- Related data, such as a student and their skills, can live in one document
- It scales well, and MongoDB Atlas gives you a free cloud database in minutes
An Example
This tutorial uses a students collection in an institute database.
Example
db.students.find(
{ city: "Lahore" },
{ _id: 0, name: 1, marks: 1 }
)[
{ name: 'Ayesha Siddiqui', marks: 85 },
{ name: 'Sana Iqbal', marks: 88 }
]What You Will Learn
- What documents, collections and databases are, and how they compare to SQL tables
- Using the MongoDB Shell (
mongosh) and MongoDB Atlas - Inserting, finding, updating and deleting documents
- Query operators such as
$gt,$inand$or - Sorting, limiting, counting and indexes
- The aggregation pipeline for reports:
$match,$group,$sortand$lookup
Knowing some JavaScript helps a lot, because MongoDB documents and shell commands use JavaScript syntax.
Exercises and Quiz
Exercise
How does MongoDB store data?
What to Learn After MongoDB
Connect MongoDB to a back-end with Node.js, and build the front-end with React. To understand relational databases too, see the SQL tutorial.
Want to learn with a teacher? The Workownix Full Stack Web Development course teaches React, Node.js and MongoDB with real projects and deployment, online or at our institute in Orangi Town, Karachi.
