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
// 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()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.