Thuta Learning
ExercisesData & Databasesintermediate

Exercises — CRUD Operations Basics

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Practice Exercises — CRUD Operations Basics on your own
  • Practice the skills you've learned to make them stick
  • Get comfortable finding bugs, fixing them, and checking your own work

Let's think about this for a second

This exercise isn't about learning anything new — it's about practicing the insert, find, update, and delete operations you covered in the Basic chapter, using the knowledge you already have. Every task will work on a single students collection. By working through the query filters, update operators, and delete methods yourself, you'll get much more comfortable with the syntax.

Exercises

Task 1: Create a new students collection and insert 4 student documents with name, age, grade, and isActive fields using insertMany(). Task 2: Use find() to look up only students whose age is over 18. Task 3: Use updateOne() to change one student's grade. Task 4: Use deleteMany() to delete all student documents where isActive: false.

Code Example

javascript
// Task 1: sample data insert လုပ်ပါ
db.students.insertMany([
  { name: "Aye Aye", age: 19, grade: "A", isActive: true },
  { name: "Ko Ko", age: 17, grade: "B", isActive: true },
  { name: "Su Su", age: 21, grade: "C", isActive: false },
  { name: "Min Min", age: 16, grade: "B", isActive: false }
])

// Task 2: age > 18 student များကို ရှာပါ (ဒီနေရာမှာ query ရေးပါ)


// Task 3: student တစ်ဦးရဲ့ grade ကို updateOne() ဖြင့် ပြောင်းပါ (ဒီနေရာမှာ update ရေးပါ)


// Task 4: isActive: false ဖြစ်သော student များကို deleteMany() ဖြင့် ဖျက်ပါ (ဒီနေရာမှာ delete ရေးပါ)
You should see
After Task 4, only student documents with isActive: true should remain in the collection.

5-Minute Try-It

Rewrite Task 2's query using the $gte operator so it includes age 18 as well — take 5 minutes and see how the results differ.

A quick word of caution

Before running deleteMany(), first run a find() with the same filter condition to confirm exactly how many documents will be affected.

Easy traps

  • Running deleteMany() without a filter condition and accidentally deleting every document in the collection
  • Storing the age field as a string ('19'), which makes $gt/$gte comparison queries return the wrong results

Now Try It Yourself

Rewrite Task 2's query using the $gte operator so it includes age 18 as well — take 5 minutes and see how the results differ.

You'll know it worked when: After Task 4, only student documents with isActive: true should remain in the collection.

Exercises — CRUD Operations Basics | Thuta Learning