← Back to MongoDB Course | Chapter 1: Introduction | Lesson 2 of 7

SQL बनाम NoSQL

SQL databases data को rows और columns की strict tables में रखते हैं, जबकि MongoDB जैसे NoSQL databases ज़्यादा flexible models इस्तेमाल करते हैं।

In this page:

  1. SQL बनाम NoSQL

SQL बनाम NoSQL

Relational databases को पहले से एक schema चाहिए, normalized tables के आर-पार joins इस्तेमाल करते हैं और SQL बोलते हैं। MongoDB related data को एक document में साथ रखता है, fields को vary होने देता है, और एक JSON query language इस्तेमाल करता है।

कोई भी generally बेहतर नहीं है: data shape, consistency needs, और team skills के आधार पर चुनें।

Note: एक SQL row roughly एक MongoDB document है, और एक table roughly एक collection।

उदाहरण: SQL vs NoSQL

bash
// SQL:   SELECT name FROM users WHERE age > 30 ORDER BY name;
// Mongo: the same question as a query document
test> db.users.insertMany([{ _id: 1, name: "Cy", age: 41 }, { _id: 2, name: "Ada", age: 36 }, { _id: 3, name: "Bob", age: 25 }])
{ acknowledged: true, insertedIds: { '0': 1, '1': 2, '2': 3 } }
test> db.users.find({ age: { $gt: 30 } }, { name: 1, _id: 0 }).sort({ name: 1 })
[ { name: 'Ada' }, { name: 'Cy' } ]

⚠️ 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. यह मान लेना कि NoSQL का मतलब है कोई transactions नहीं
  2. यह मान लेना कि SQL scale नहीं कर सकता
  3. एक relational schema को बिना बदले MongoDB में copy करना
चैप्टर सारांश
  • SQL tables, rows, और joins इस्तेमाल करता है
  • MongoDB collections और documents इस्तेमाल करता है
  • MongoDB documents shape में vary हो सकते हैं
  • Data और access patterns के आधार पर चुनें
🔒

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.