← Back to MongoDB Course | Chapter 2: CRUD — Create | Lesson 3 of 7

Document की संरचना

Documents nested documents और arrays hold कर सकते हैं, इसलिए related data साथ रह सकता है।

In this page:

  1. Document Structure
Syntax
javascript
db.collection_name.insertOne({
  field: value,
  subdocument: { key: value },
  array: [value1, value2]
})

Document Structure

Parent से belong करने वाले data के लिए sub-documents embed करें और values की lists या objects के छोटे sets के लिए arrays। Field names strings हैं, और dotted paths nested data तक पहुँचते हैं। एक document 16 MB तक हो सकती है, इसलिए unbounded arrays risky हैं।

Note: Documents को 16 MB limit से काफी नीचे रखें और हमेशा बढ़ने वाले arrays से बचें।

उदाहरण: Document structure

bash
test> db.orders.insertOne({
...   _id: 100,
...   customer: { name: "Ada", email: "[email protected]" },
...   items: [{ sku: "PEN", qty: 2, price: 3 }, { sku: "LAMP", qty: 1, price: 45 }],
...   status: "paid"
... })
{ acknowledged: true, insertedId: 100 }
test> db.orders.findOne({ "customer.name": "Ada" }, { status: 1, "items.sku": 1 })
{
  _id: 100,
  items: [ { sku: 'PEN' }, { sku: 'LAMP' } ],
  status: 'paid'
}

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Unbounded arrays बनाना
  2. $ से शुरू होने वाले या dots रखने वाले field names इस्तेमाल करना
  3. बिना query need के deeply nesting करना
चैप्टर सारांश
  • Related data embed करें
  • Arrays lists hold करते हैं
  • Dotted paths nested fields तक पहुँचते हैं
  • Documents 16 MB तक limited हैं
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.