MongoDB Academy · บทเรียน

คอขวดของฐานข้อมูลเชิงสัมพันธ์

ผู้เรียนจะระบุข้อจำกัดด้านการขยายระบบและความยืดหยุ่นของฐานข้อมูล SQL ซึ่งเป็นแรงผลักดันให้เกิดกระแส NoSQL

บทเรียน 1 จาก 413 ขั้นตอน

คอขวดของฐานข้อมูลเชิงสัมพันธ์ เป็นบทเรียน MongoDB Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน MongoDB Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส MongoDB Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Rise of Relational Databases

For decades, relational databases like MySQL and PostgreSQL ruled. They store data in neat tables of rows and columns, and they work great. So why look further?

The Rigid Schema Problem

SQL tables use a rigid schema: you must define every column up front. Changing it later means a migration that can lock the table and cause downtime.

-- Adding a column to a large table in PostgreSQL can be slow
ALTER TABLE users ADD COLUMN preferences JSONB;
-- On 100M rows this may require a full table rewrite
-- and blocks reads/writes for minutes

Scaling Up vs. Scaling Out

To grow, SQL usually scales up — a bigger, pricier server. But there's a ceiling. Modern apps need to scale out across many machines, which SQL handles awkwardly.

JOIN Performance at Scale

SQL splits data across tables and stitches it back with JOINs. That's fine when small, but on huge data, joining five tables per query gets slow.

-- A typical normalized SQL query joining 4 tables
SELECT o.id, c.name, p.title, oi.quantity
FROM orders o
JOIN customers c ON c.id = o.customer_id
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON p.id = oi.product_id
WHERE o.status = 'pending';

The High-Traffic Write Problem

SQL locks rows to keep data safe with ACID transactions. Great for banks, but those locks struggle when you need millions of writes per second.

Unstructured and Semi-Structured Data

The web is full of semi-structured data like messy JSON. Forcing it into fixed columns means tons of empty fields or awkward workarounds.

-- EAV table: flexible but awkward to query
CREATE TABLE product_attributes (
  product_id INT,
  attr_name  VARCHAR(50),
  attr_value VARCHAR(200)
);
-- Querying all electronics by voltage is painful:
SELECT * FROM product_attributes
WHERE attr_name = 'voltage' AND CAST(attr_value AS INT) > 100;

The Internet Scale Wake-Up Call

Around 2006, Google and Amazon hit real scaling walls and published their fixes. That sparked a whole new wave: NoSQL databases built for internet scale.

What NoSQL Does Differently

NoSQL trades some SQL rules for new strengths: flexible schemas, easy scaling across machines, and fast writes. Not always better — just optimized differently.

When RDBMS Still Wins

SQL still wins plenty: financial transactions, complex reports, and stable data. Most apps never outgrow a well-tuned PostgreSQL. Right tool for the job!

The Document Model as a Solution

MongoDB's answer is the document model. Instead of splitting a user across five tables, it stores everything together in one JSON-like document. The code below shows one.

// A MongoDB document stores related data together
{
  _id: ObjectId('...'),
  name: 'Alice',
  email: 'alice@example.com',
  address: { city: 'London', zip: 'EC1A' },
  tags: ['premium', 'newsletter'],
  createdAt: ISODate('2024-01-15')
}

Horizontal Scaling Is Built In

MongoDB scales out with sharding — adding servers as you grow. Replica sets keep copies live, so if one node fails, another takes over automatically.

Quick Check

Test your understanding of MongoDB & NoSQL Databases concepts from this lesson.

Lesson Recap

You saw why SQL bottlenecks at huge scale, where JOINs and heavy writes hurt most, and how MongoDB's document model fixes it. Next: the four NoSQL families.

เริ่มต้นได้ฟรี

เรียนรู้ JavaScript ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
30
บทเรียน
120

คำถามที่พบบ่อย

บทเรียน “คอขวดของฐานข้อมูลเชิงสัมพันธ์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “คอขวดของฐานข้อมูลเชิงสัมพันธ์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส MongoDB Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส MongoDB Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “คอขวดของฐานข้อมูลเชิงสัมพันธ์”

ผู้เรียนจะระบุข้อจำกัดด้านการขยายระบบและความยืดหยุ่นของฐานข้อมูล SQL ซึ่งเป็นแรงผลักดันให้เกิดกระแส NoSQL คุณปฏิบัติ MongoDB Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน MongoDB Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน MongoDB Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน

บทเรียน “คอขวดของฐานข้อมูลเชิงสัมพันธ์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน MongoDB Academy นี้ได้ไหม

ได้ บทเรียน MongoDB Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. คอขวดของฐานข้อมูลเชิงสัมพันธ์
  2. รูปแบบของ NoSQL: เอกสาร คีย์-ค่า คอลัมน์ กราฟ
  3. ทฤษฎีบท CAP แบบเข้าใจง่าย
  4. MongoDB เหมาะกับงานใด
← กลับไปที่ MongoDB Academy