Tech TutorBangla Web Documentation
Portfolio
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • MongoDB Documentation21টি অধ্যায়
প্রযুক্তি নির্বাচন
HomeHTMLCSSTailwind CSSJavaScriptTypeScriptReactNext.jsNode.jsExpressSocket.IOExpoWordPressPostgreSQLPrismaPostgresNestJSMongoDBDockerTanStackTanStack TableRTK QueryGitGitHub
  • Introduction
  • কেন Mongoose?
  • Installation
  • Connection
  • Schema
  • Model
  • Document
  • CRUD
  • Querying
  • Validation
  • Middleware
  • Population
  • Aggregation
  • Virtuals
  • Indexes
  • Error Handling
  • Update Operators
  • Transactions
  • Express Integration
  • Blog Project
  • Best Practices
  1. Docs
  2. MongoDB
  3. Update Operators ($set, $inc, $push…)
MongoDBIntermediate

Update Operators ($set, $inc, $push…)

MongoDB update operator-গুলোর ব্যবহার: $set, $inc, $push, $pull, $addToSet, upsert — বাংলায়।

9টি অংশবাংলা ভাষায়

Operator-গুলো

Operatorকাজ
$setfield-এর value বসান
$unsetfield মুছে ফেলুন
$incসংখ্যা বাড়ান/কমান
$mulগুণ করুন
$pusharray-তে value যোগ করুন
$pullarray থেকে নির্দিষ্ট value সরান
$addToSetarray-তে যুক্ত করুন (ডুপ্লিকেট ছাড়া)
$min / $maxছোট/বড় value রাখুন

Numeric operators

$set, $inc, $unsetjs
js
// title ঠিক করুন, views ১ বাড়ান, pending field-টা সরান
await Post.updateOne(
  { _id: postId },
  {
    $set: { title: "আপডেটেড টাইটেল" },
    $inc: { views: 1 },
    $unset: { pending: "" },
  }
);

// পূর্বের value দেখে update: $inc atomic — race-safe
await Account.updateOne(
  { _id: accId },
  { $inc: { balance: -100 } }
);

Array operators

$push, $pull, $addToSetjs
js
// comment যোগ
await Post.updateOne(
  { _id: postId },
  { $push: { comments: commentId } }
);

// নির্দিষ্ট comment সরান
await Post.updateOne(
  { _id: postId },
  { $pull: { comments: commentId } }
);

// duplicate ছাড়া tag যোগ
await Post.updateOne(
  { _id: postId },
  { $addToSet: { tags: "mongoose" } }
);

// $push-এ position সহ — সামনে বসান
await Post.updateOne(
  { _id: postId },
  { $push: { comments: { $each: [newCommentId], $position: 0 } } }
);

upsert

নেই থাকলে insertjs
js
// মতো filter-এর document না থাকলে নতুন document তৈরি হয়
await LoginAttempt.updateOne(
  { userId, date: today },
  { $inc: { count: 1 } },
  { upsert: true }
);
update operators + findOneAndUpdate

findOneAndUpdate-এর সাথে operator ছাড়া (যেমন { title: "..." }) সরাসরি value বসালে পুরো document replace হয়ে যেতে পারে। সবসময় $set ইত্যাদি operator ব্যবহার করুন — options.overwrite পুরো প্রতিস্থাপনের জন্য দরকার।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরError HandlingপরেরTransactions (Multi-Document ACID)
এই পেজে
Tech Tutor

বাংলায় ওয়েব ডেভেলপমেন্ট ডকুমেন্টেশন শিখুন — ধাপে ধাপে।

Homeসব ডকুমেন্টেশনQuick Startআমার নোটস

© 2026 Tech Tutor. বাংলায় শিখুন, বাংলায় গড়ুন।

mdanamolhasan1998@gmail.com