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. Schema ডিফাইন
MongoDBBeginner

Schema ডিফাইন

Mongoose Schema কী, field type, nested schema, options এবং এর পুরো নিয়ম — বাংলায়।

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

Schema কী?

Schema হলো document-এর blueprint — কোন field থাকবে, কী type-এর হবে, কোনটা required — সবই এখানে define করা হয়। Schema থেকেই পরে Model তৈরি হয়।

সাধারণ schemajs
js
import mongoose from "mongoose";

const userSchema = new mongoose.Schema({
  name: { type: String, required: true },
  email: { type: String, required: true, unique: true, lowercase: true },
  age: { type: Number, min: 13 },
  isActive: { type: Boolean, default: true },
  tags: { type: [String], default: [] },
  createdAt: { type: Date, default: Date.now },
});

Built-in Types

Typeব্যবহার
StringText, email, name
Numberসংখ্যা (int/float)
Dateতারিখ ও সময়
Booleanসত্য/মিথ্যা
BufferBinary data (photo, file)
ObjectIdঅন্য document-এর reference
ArrayList of values
Mixedযেকোনো type (যত্নে ব্যবহার করুন)
Decimal128নিখুঁত decimal (money)
MapDynamic key-value object

Nested Schema

Nested + array of objectsjs
js
const addressSchema = new mongoose.Schema({
  city: String,
  zip: String,
  country: { type: String, default: "BD" },
});

const userSchema = new mongoose.Schema({
  name: String,
  address: addressSchema, // nested document
  orders: [
    {
      product: { type: String, required: true },
      quantity: { type: Number, default: 1 },
    },
  ], // array of subdocuments
});

Schema Options

Timestamps সহjs
js
const postSchema = new mongoose.Schema(
  {
    title: { type: String, required: true },
    body: String,
  },
  {
    timestamps: true, // createdAt, updatedAt নিজে থেকেই যুক্ত হয়
    versionKey: false, // __v field না রাখতে
    strict: true,      // schema-তে নেই এমন field নেবে না (default)
  }
);
strict: false সাবধানে

strict: false দিলে schema-তে নেই এমন field-ও save হবে — যা অবাঞ্ছিত ডেটা জমা করে। সাধারণত strict: true (default) রেখে দরকারি field স্পষ্টভাবে বাড়ান।

শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।
আগেরMongoDB-র সাথে ConnectionপরেরModel তৈরি
এই পেজে
Tech Tutor

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

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

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

mdanamolhasan1998@gmail.com