Theory
जब Rows और Columns आपके Data से लड़ें
BCA205 और BCA303 में आपने data TABLES में store किया: fixed columns, हर row same shape, related tables साथ joined। यह powerful और precise है।
पर FestConnect के events एक table में awkward हैं: एक cultural event का एक dress code है, एक coding contest की एक programming-language list है, एक workshop की एक materials list है। अलग events, अलग fields। इन्हें एक rigid table में force करना मतलब है dozens of mostly-empty columns।
यहीं NoSQL databases shine करते हैं: ये rigid rows की बजाय flexible, self-describing documents store करते हैं। यह unit FestConnect का data MongoDB पर rebuild करता है, और यह शुरू होता है WHY NoSQL exist करता है।
Theory
NoSQL, Formally
NoSQL (अक्सर 'Not Only SQL' या 'non-relational' पढ़ा जाता है) databases relational databases के fixed table-row-column schema के WITHOUT data store करते हैं।
4 main types हैं:
- Document (MongoDB): data JSON-like documents की तरह: इस unit का focus
- Key-value (Redis): simple key से value pairs
- Column-family (Cassandra): flexible columns वाली rows
- Graph (Neo4j): nodes और relationships
Unifying idea: rigid schema drop करना। जहाँ एक relational database हर event को ONE table shape fit करने demand करता है, एक document database हर event को अपना खुद का flexible document होने देता है जिन्हें जो भी fields चाहिए हों।
At a glance
Relational (SQL) बनाम NoSQL
| Aspect | Relational (SQL) | NoSQL |
|---|---|---|
| Structure | Fixed tables, rows, columns | Flexible: documents, key-values, वग़ैरह |
| Schema | Strict, पहले से defined | Flexible या schema-less |
| Relationships | Tables के across JOINs | अक्सर embedded/denormalised, कोई joins नहीं |
| Scaling | आमतौर पर vertical (बड़ा server) | Horizontal (servers के across scale out) |
| इसके लिए Best | Complex transactions, strict consistency | Large-scale, बदलता, unstructured data |
Theory
Advantages और Features
Teams NoSQL क्यों पहुँचती हैं:
- flexible schema: fields हर record में vary कर सकती हैं, तो data model painful migrations के बिना evolve होता है
- horizontal scalability: servers add करके OUT scale कीजिए, बहुत बड़ा data और traffic handle करते हुए
- कई read/write-heavy workloads के लिए high performance
- naturally unstructured/semi-structured data handle करता है
- developer-friendly: documents program objects से cleanly map होते हैं (एक MongoDB document एक JavaScript object जैसा दिखता है)
एक honest trade-off नाम लेने लायक: कई NoSQL systems strict consistency (वह ACID guarantees जो relational databases prize करते हैं) को availability और scale के favour में relax करते हैं। तो NoSQL universally 'better' नहीं है: यह trade-offs का एक अलग set है, और relational databases complex transactions और strict consistency के लिए सही choice बने रहते हैं।
Quiz
Relational databases की तुलना में NoSQL databases की कौन सी defining characteristic है?
- ये हमेशा strict schemas वाली fixed tables में data store करते हैं
- ये flexible, non-tabular structures (documents जैसी) इस्तेमाल करते हैं, अक्सर बिना एक rigid schema या joins के
- ये कोई structured data बिल्कुल store नहीं कर सकते
- ये हर situation में हमेशा relational databases से faster होते हैं
Show the answer
ये flexible, non-tabular structures (documents जैसी) इस्तेमाल करते हैं, अक्सर बिना एक rigid schema या joins के
NoSQL का defining trait flexible, NON-tabular storage है (documents, key-values, columns, graphs) आमतौर पर बिना एक rigid predefined schema के और अक्सर बिना joins के: option A जो describe करता है उसका opposite (वह relational है)। Option C इसे overstate करता है: NoSQL structured और semi-structured data अच्छी तरह handle करता है; यह बस एक rigid shape FORCE नहीं करता। Option D वह 'NoSQL हमेशा बेहतर है' myth है जो यह lesson refute करता है: NoSQL scale और flexibility के लिए जीतता है पर कुछ consistency guarantees trade away करता है, और complex transactions के लिए relational databases अभी भी बेहतर हैं। Honest framing: अलग trade-offs, universal superiority नहीं।
Think first
FestConnect के Events Documents को क्यों Suit करते हैं
FestConnect में cultural events, coding contests, और workshops हैं, हर एक अलग extra fields के साथ। Explain कीजिए एक document database इसे एक rigid table से बेहतर क्यों handle करता है। फिर tap कीजिए।
Show the answer
एक RELATIONAL table में, हर event को ONE column set share करना पड़ता है, तो आप या तो हर possible field के लिए एक column वाली एक giant table बनाते हैं (dress code, language list, materials...), जिनमें से ज़्यादातर किसी भी given event के लिए empty हैं, या आप कई joined tables में split करते हैं: दोनों clumsy। एक DOCUMENT database में, हर event अपना OWN document है exactly उन fields के साथ जो इसे चाहिए: Garba document में एक dressCode field है, coding-contest document में एक languages array है, workshop document में एक materials list है, और कोई भी दूसरों की empty fields carry नहीं करता। Flexible schema naturally-varying data fit करता है। उस कहा, अगर data highly uniform और transaction-heavy होता (bank accounts जैसा), एक relational table बेहतर tool होता। Database को data की shape से match कीजिए।
Watch out
NoSQL Misconceptions
'NoSQL मतलब कोई SQL-like queries नहीं': कई NoSQL systems में rich query languages हैं; नाम का मतलब non-relational है, query-less नहीं।
'NoSQL हमेशा बेहतर/faster है': यह consistency को scale/flexibility के लिए trade करता है; complex transactions के लिए relational बेहतर है।
'Schema-less मतलब कोई structure नहीं': documents में अभी भी structure है; यह बस flexible है, पहले से enforced नहीं।
Trade-off भूलना: relaxed consistency (eventual consistency) कई NoSQL systems में एक real cost है; अपनी consistency needs जानिए।
Theory
Concept से MongoDB तक
अब आप समझते हैं WHY NoSQL exist करता है: उस data के लिए flexible, scalable storage जो rigid tables resist करता है। Unit 1 का बाकी हिस्सा सबसे popular document database, MongoDB के साथ concrete होता है: इसके data types और databases और collections कैसे create और drop करें, फिर full CRUD (create, read, update, delete) और query, projection और aggregation operators। FestConnect के events अभी MongoDB documents बनने वाले हैं। फिर React और Angular इस पर modern UI build करते हैं।
Summary
Key takeaways
- NoSQL databases relational databases की rigid tables की बजाय flexible, non-tabular structures में data store करते हैं।
- 4 main types: document (MongoDB), key-value, column-family, graph।
- Relational के मुक़ाबले: flexible/schema-less बनाम strict schema; embedded data बनाम joins; horizontal बनाम vertical scaling।
- Advantages: flexible schema, horizontal scalability, high performance, unstructured data handle करना, objects से map होना।
- Trade-off: कई NoSQL systems availability और scale के लिए strict consistency (ACID) relax करते हैं।
- NoSQL universally बेहतर नहीं है: complex transactions और strict consistency के लिए relational अभी भी best है।
- Memory hook: NoSQL rigid table drop करके flexible documents देता है, strict consistency को scale से trade करते हुए।