Skip to Content

MongoDB Fundamentals

Module Summary

This module introduces learners to NoSQL databases with a focus on MongoDB and data management using Mongoose. It covers the fundamental concepts of NoSQL, including document databases, collections, and documents. Learners will perform CRUD (Create, Read, Update, Delete) operations using Mongoose and Express. By the end of the module, learners will have the ability to create, query, and manage data using MongoDB and Mongoose in a Node.js backend.

Learning Objectives

  • Explain the fundamentals of NoSQL and MongoDB.
  • Use Mongoose for schema modeling and database management.
  • Perform CRUD operations in an Express application using Mongoose.

Learning Outcomes

Learners will be able to perform CRUD operations and manage data using MongoDB and Mongoose.


Module Outline

Lesson 1: Introduction to NoSQL & MongoDB

  • Time: 2.5 hours
  • Topics:
    • Fundamentals of NoSQL databases and comparison with SQL.
    • Introduction to MongoDB architecture (collections, documents).
  • Activities:
    • Exploring a MongoDB database with Compass.
  • Knowledge Check:
    • Multiple-choice questions on core NoSQL and MongoDB concepts.

Lesson 2: MongoDB Atlas & Connecting an App

  • Time: 3 hours
  • Topics:
    • Introduction to MongoDB Atlas for cloud-hosted databases.
    • Connecting a Node.js application to a MongoDB database.
    • Securing connection strings with environment variables.
  • Activities:
    • Set up a MongoDB Atlas cluster and connect it to a Node.js application.
  • Knowledge Check:
    • Debugging common connection issues.

Lab 1: Connecting a Database

  • Time: 2 hours (asynchronous)
  • Task: You have been asked to connect a new Node.js/Express application to a MongoDB Atlas cluster.
  • Objective: By the end of this activity, you will have demonstrated your ability to set up a MongoDB Atlas cluster and connect it to a Node.js/Express application, securing the connection string.

Lesson 3: Mongoose Schemas & Models

  • Time: 2.5 hours
  • Topics:
    • Introduction to Mongoose as an ODM (Object Data Modeling) library.
    • Defining schemas and models.
    • Data Types, Validation, and Schema Constraints.
  • Activities:
    • Define schemas and models for a resource (e.g., a “Product” or “User”).
  • Knowledge Check:
    • Scenario-based questions on schema design and data validation.

Lesson 4: Basic CRUD with Mongoose

  • Time: 3 hours
  • Topics:
    • Basic CRUD Operations: create, findById, findByIdAndUpdate, findByIdAndDelete.
    • Handling errors from database operations.
  • Activities:
    • Build a simple RESTful API with endpoints for all CRUD operations.
  • Knowledge Check:
    • Code challenges to implement specific CRUD endpoints.

Lab 2: Mongoose Models and Schemas

  • Time: 2 hours (asynchronous)
  • Task: You have been asked to build a full CRUD API using Mongoose.
  • Objective: By the end of this activity, you will demonstrate the ability to build a full CRUD API using Mongoose for data modeling, validation, and database operations.

Lesson 5: Advanced Mongoose Querying

  • Time: 2.5 hours
  • Topics:
    • Querying with operators ($gt, $in, etc.).
    • Projections (selecting specific fields).
    • Sorting and pagination.
  • Activities:
    • Write complex queries to filter and sort data in a RESTful API.
  • Knowledge Check:
    • Given a dataset and requirements, write the correct Mongoose query.

Assessments

Skills-Based Assessment (SBA)

  • Time: 5.5 hours
  • Format: Practical project
  • Activity: Build an Express API with a MongoDB database, using Mongoose for data management. Design a RESTful API with CRUD operations for managing a collection of products. Ensure data validation using Mongoose schemas and use best practices for error handling and API structuring.
  • Deliverable: Project repository with a README explaining setup steps and a MongoDB Atlas connection string secured with environment variables.
  • Rubric: Evaluation based on correct CRUD operations implementation, proper schema design and validation using Mongoose, clear project structure, error handling, security, and code readability.

Knowledge-Based Assessment (KBA)

  • Time: 1.5 hours (asynchronous)
  • Format: Multiple-choice and short-answer questions covering all major topics from the module, including NoSQL concepts, MongoDB, Mongoose schemas, and CRUD operations.