Thuta Learning
ProjectsData & Databasesintermediate

Mini Project: Task Manager Database — Part 2 (Query and Update Features)

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

What you'll walk away with

  • Apply Mini Project: Task Manager Database — Part 2 (Query and Update Features) in a hands-on project
  • Write and run your own code
  • Build out an entire project step by step

Let's think about this for a moment

In a task manager application, some of the most common features are filtering by status, marking a task as complete, and finding overdue tasks. In this lesson, you'll get hands-on practice with query filters, comparison operators ($lt, $gt), update operators ($set, $currentDate), and updateOne/updateMany, using the data from Part 1. In a real app, this is exactly the kind of query the backend runs whenever a user filters, searches, or updates something, so this practice closely mirrors production code. Once you can write query and update logic correctly, you'll also have a solid foundation for the aggregation reports in Part 3.

Let's build it hands-on

First, try filtering with find() for tasks where status: "pending" and priority: "high". Next, find a task by its title and use updateOne() to change its status to "completed" — use the $set operator together with the $currentDate operator to automatically add an updatedAt timestamp field. Finally, use updateMany() to flag overdue: true on every task whose dueDate is earlier than today and whose status is still "pending" — use the comparison operator dueDate: { $lt: new Date() } in your filter.

Code Example

javascript
// status = pending နှင့် priority = high ဖြစ်တဲ့ task များကို ရှာပါ
db.tasks.find({ status: "pending", priority: "high" })

// task တစ်ခုကို completed ပြောင်းပြီး updatedAt timestamp ထည့်ပါ
db.tasks.updateOne(
  { title: "Fix login bug" },
  {
    $set: { status: "completed" },
    $currentDate: { updatedAt: true }
  }
)

// dueDate ကျော်နေတဲ့ pending task အားလုံးကို overdue flag တင်ပါ
db.tasks.updateMany(
  { status: "pending", dueDate: { $lt: new Date() } },
  { $set: { overdue: true } }
)

// ပြောင်းလဲမှုများကို confirm လုပ်ပါ
db.tasks.find().pretty()
You should see
After each updateOne() and updateMany() run, matchedCount and modifiedCount are returned, and running find() again shows the status, updatedAt, and overdue fields have changed.

5-minute try-it

Find tasks with priority: "low" and use updateMany() to change all of their priority to "medium" at once — spend 5 minutes checking whether matchedCount and modifiedCount differ.

A quick word of caution

Before running updateMany() on production data, test your filter condition with find() first and carefully check exactly which documents it will touch — too broad a filter can end up updating far more documents than you intended.

Easy traps

  • Using updateOne() even when you meant to change many documents, without noticing that it only updates a single document
  • Writing the update value directly without the $set operator, causing the entire document (all its fields) to get replaced

Now try it yourself

Find tasks with priority: "low" and use updateMany() to change all of their priority to "medium" at once — spend 5 minutes checking whether matchedCount and modifiedCount differ.

You'll know it worked when: After each updateOne() and updateMany() run, matchedCount and modifiedCount are returned, and running find() again shows the status, updatedAt, and overdue fields have changed.

Mini Project: Task Manager Database — Part 2 (Query and Update Features) | Thuta Learning