MongoDB: Schema Validation

Level : Advanced
Mentor: Shailendra Chauhan
Type : GuidedLab
Points : 10
Duration : 00:20:00

Lab Details

Problem Statement:

Develop a MongoDB collection named "employee" with a schema validation to ensure each document includes the necessary fields "FirstName", “LastName” and "age".

Apply Validation on the below given fields:

  • "FirstName" and “LastName” must be a string,
  • "Salary" must be a number between 40,000 and 50,000.

The collection should use a moderate validation level for enforcing these rules.

Apply Schema Validation through MongoDB Compass as well as MongoDB Shell.

Lab Objective:

Upon completion of this lab, you will be able to:

  • Defining Schema Validation.
  • Use MongoDB Compass to define the schema validation on various fields.
  • Use MongoDB shell to define the schema validation on various fields.

Prerequisites

You should install following software on your machine:

  • MongoDB Server 7 or higher
  • MongoDB Shell
  • MongoDB Compass


Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
CONTACT US
Accept cookies & close this