0% found this document useful (0 votes)
4 views43 pages

NoSQL Databases Overview and Insights

Uploaded by

saleh.hassan313
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views43 pages

NoSQL Databases Overview and Insights

Uploaded by

saleh.hassan313
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

‫‪CSC 301 / Advanced Databases‬‬

‫‪NoSQL Databases‬‬
‫)‪Companion Notes (EN + AR‬‬
‫شرح عربي ُمكّثف ‪ +‬مصطلحات إنجليزي ‪ +‬أسئلة مراجعة قصيرة بعد كل جزء‪.‬‬
‫الهدف‪ :‬تفهم الفكرة وتعرف تختار اإلجابة الصح في امتحان الـ ‪.MCQ‬‬
Slide 1 - Lecture overview: Why NoSQL exists

Figure: Original slide 1 (for reference)

Slide text (extracted):

NOSQL DATABASES

:)‫الشرح بالعربي (المهم لالمتحان‬

‫ في أنظمة الويب‬Relational DBMS ‫ ليه ناس كتير بطلت تستخدم الـ‬:‫المحاضرة دي بتجاوب سؤال بسيط‬
‫الضخمة؟‬

‫ توزيع على‬+ ‫ لكن مع حجم بيانات ضخم‬.‫ ممتاز في حاجات كتير‬،‫ بالعكس‬.‫ وحش‬RDBMS ‫الفكرة مش إن الـ‬
.‫ بتبدأ تتكسر‬RDBMS ‫ بعض افتراضات الـ‬،‫ عالية‬Availability ‫ متطلبات‬+ ‫سيرفرات كتير‬

Document, Key- :‫ هو مظلة لكل قواعد البيانات غير العالئقية‬.)‫ حرفًيا‬No SQL( ‫ مش معناه‬NoSQL ‫مصطلح‬
…Value, Column-Family, Graph

English clarification (quick):

NoSQL is an umbrella term for non-relational DBMSs designed for web-scale, distributed, horizontally scalable
systems.
You will keep seeing the tradeoff: strong consistency (ACID) vs high availability and partition tolerance (often
BASE/eventual consistency).

Mini-check (MCQ):

What is the best definition of 'NoSQL' in this course?

 A) A DBMS that does not support SQL


 B) An umbrella term for non-relational DBMSs
 C) A specific database product
 D) A replacement for normalization

Correct answer: B

Explanation: Because the slides explicitly treat NoSQL as an umbrella term for non-relational DBMSs and
alternatives to relational data organization.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 2 - Advantages of RDBMSs (and why they were dominant)

Figure: Original slide 2 (for reference)

Slide text (extracted):

Advantages of RDBMSs
redundancy
understood and offer strong guarantees of data
consistency.
mature, robust, efficient and fully featured
pieces of software.

 Strong theoretical basis


 Store information efficiently
 They guard against data duplication and
 Transactions in relational databases are well
 The relational database engines themselves are

:)‫الشرح بالعربي (المهم لالمتحان‬

‫ ده بيخليك‬.)Relational model, normalization, keys, constraints ( ‫ عنده أساس نظري قوي‬RDBMS ‫الـ‬
.)redundancy( ‫تبني تصميم منظم وتقلل التكرار‬
‫ أدوات‬،‫ كتير‬features ،‫ كويس‬performance :‫) ومجربة سنين‬mature( ‫ ومحركاته ناضجة‬،‫بيخزن البيانات بكفاءة‬
.‫ قوية‬backup/recovery

.)ACID( ‫ قوية‬consistency ‫) مفهومة جًدا وبتديك ضمانات‬transactions( ‫ معامالت‬:‫وأهم حاجة‬

English clarification (quick):

Key selling points: mature engines, efficient storage, reduced redundancy, and strong transactional
guarantees.

Mini-check (MCQ):

Which is NOT typically listed as a core advantage of relational DBMSs?

 A) Mature and fully featured engines


 B) Strong data consistency through transactions
 C) Completely schema-free data model
 D) Good protection against duplication/redundancy

Correct answer: C

Explanation: Schema-free is usually a NoSQL trait; relational systems are schema-based.

:Exam tip

.‫ قوية‬ACID ‫ معامالت‬+ ‫ تقليل التكرار‬:‫ أكتر إجابتين بيحبهم األستاذ‬:RDBMS ‫لو السؤال عن مزايا‬
Slide 3 - Assumptions behind relational DBMSs

Figure: Original slide 3 (for reference)

Slide text (extracted):

2.1 Assumptions behind relational


databases and RDBMSs
interacting with the database must reflect that

 data can be broken down into sets of records


 every record contains the same types of data (fields)
 each field of each record holds atomic data
 records make sense on their own
 the data is more important than its relationships
 data is regularly written to and read from the database
 the database must always be internally consistent
 the database is the ‘single point of truth’ and the results of
 the DBMS can see all of the data at once.

:)‫الشرح بالعربي (المهم لالمتحان‬

.‫ هيبقى مش مريح‬RDBMS ‫ الـ‬،‫الساليد دي خطيرة في االمتحان ألنها بتديك 'افتراضات' لو اتكسرت‬


‫ والقيم‬،)‫ ثابت‬schema( ‫ نفس أنواع الحقول‬Record ‫ وكل‬،Records ‫ البيانات عبارة عن‬:‫افتراضات مهمة‬
.‫ طول الوقت‬internally consistent ‫ الزم تفضل‬DB ‫ والـ‬،)list ‫ (قيمة واحدة مش‬Atomic

‫متقطعة‬/‫ يقدر يشوف كل البيانات مرة واحدة (مش موزعة‬DBMS ‫ والـ‬،single point of truth ‫ هي‬DB ‫ الـ‬:‫كمان‬
.)network partitions ‫بسبب‬

‫' غالًبا مرتبط بالـ‬always consistent' ‫' و‬atomic values' ‫ ثابت' و‬schema' ‫ أي اختيار بيقول‬:‫امتحانًيا‬
.RDBMS

English clarification (quick):

Relational systems work best when data fits a fixed schema and atomic fields, with strong consistency and
centralized visibility.

Mini-check (MCQ):

Which assumption aligns MOST with the relational model?

 A) Records may have completely different schemas in the same table


 B) Each field holds atomic data
 C) System is designed for frequent network partitions
 D) Data is primarily represented as nested documents

Correct answer: B

Explanation: Atomic fields are a core relational assumption; the others are typical reasons to consider NoSQL.

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 4 - Assumptions can be relaxed (but not for free)

Figure: Original slide 4 (for reference)

Slide text (extracted):

2.1 Assumptions behind relational


databases and RDBMSs
assumptions.

 Some assumptions can be relaxed in practice:


 atomic data
 each record fits the same schema
 But relational DBMSs work best if they fit these
 these assumptions may no longer hold
 alternatives to the RDBMS may be more appropriate.

:)‫الشرح بالعربي (المهم لالمتحان‬

schema ‫ أو‬atomic data ‫) زي‬relax( ‫ ممكن تتراخى‬RDBMS ‫ في الواقع بعض افتراضات الـ‬:‫هنا بيقولك‬
…JSON columns ‫ أو بعض األنظمة تدعم‬،NULLs ‫ يعني تقدر تستخدم‬.strictness

،‫ لو البيانات 'مش ماشية' على االفتراضات‬.‫ بيشتغل أحسن لما االفتراضات دي تكون متحققة‬RDBMS ‫ الـ‬:‫بس‬
.‫هتتعب في التصميم واألداء‬
.‫ ممكن تكون أنسب‬RDBMS (NoSQL) ‫ للـ‬hold، alternatives ‫ دي ماعادتش‬assumptions ‫ لو‬:‫الخالصة‬

English clarification (quick):

Relaxing relational assumptions is possible, but relational DBMSs are optimized for the classic assumptions.

Mini-check (MCQ):

The slides suggest that relational DBMSs work best when:

 A) Assumptions like atomic data and fixed schema hold


 B) Data is always stored as nested structures
 C) There is no need for consistency
 D) Every table is fully denormalized

Correct answer: A

Explanation: They explicitly say relational DBMSs work best if the assumptions fit.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 5 - NoSQL: alternatives to the relational model

Figure: Original slide 5 (for reference)

Slide text (extracted):

3 Alternatives to the relational model:


NoSQL databases
persistent data.

 What is ‘NoSQL’?
 an umbrella term for all non-relational DBMSs.
 many alternatives to the relational way of organizing

:)‫الشرح بالعربي (المهم لالمتحان‬

.‫ غير عالئقي‬DBMS ‫ لكل‬umbrella term :‫ هنا واضح‬NoSQL ‫تعريف‬

.‫ غير جدول وصفوف وأعمدة‬persistent ‫الفكرة إن فيه طرق كتير لتنظيم البيانات بشكل‬

.Key-Value، Column-Family، Graph، Document :‫األنواع المشهورة اللي بتظهر في الصورة‬

English clarification (quick):

NoSQL groups multiple models: key-value, document, column-family, graph.


Mini-check (MCQ):

Which of these is a common NoSQL model mentioned in the slides?

 A) Document
 B) Spreadsheet
 C) Flat file only
 D) Only relational

Correct answer: A

Explanation: Document databases are explicitly shown as a NoSQL category.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 6 - NoSQL characteristics vs relational

Figure: Original slide 6 (for reference)

Slide text (extracted):

NoSQL databases
From [Link]:
Next Generation Databases mostly addressing some of the points:
being non-relational, distributed, open-source and horizontal
scalable. The original intention has been modern web-scale
databases. The movement began early 2009 and is growing
rapidly. Often more characteristics apply as: schema-free, easy
replication support, simple API, eventually consistent / BASE
(not ACID), a huge data amount, and more.

 Many NoSQL databases are aggregate-oriented.


 Relational databases are fragmented, normalised.
 NoSQL databases are Schema Free.
 Relational databases are schema based.

:)‫الشرح بالعربي (المهم لالمتحان‬

Distributed, Open-source, ‫ غالًبا‬[Link]: NoSQL ‫الساليد دي جايبة وصف من موقع‬


.Horizontal scalable
schema-free، replication support، simple API، eventual consistency/BASE :‫خصائص كتير بتتكرر‬
.ACID، huge data amount ‫بدل‬

‫ كوحدات كبيرة‬data ‫' يعني بتخزن‬NoSQL 'aggregate-oriented ‫ كتير من‬:‫نقطة مهمة‬


.relational ‫ زي الـ‬normalise‫) و‬fragment( ‫) بدل ما تفككها‬documents/aggregates(

English clarification (quick):

NoSQL often targets horizontal scalability and distributed systems; many systems favor BASE/eventual
consistency.

Aggregate-oriented storage contrasts with normalized fragmentation in relational design.

Mini-check (MCQ):

Which pairing matches the slide's comparison?

 A) Relational: schema-free, NoSQL: schema-based


 B) Relational: normalized/fragmented, NoSQL: aggregate-oriented
 C) Relational: BASE, NoSQL: ACID
 D) Relational: simple API, NoSQL: SQL-only

Correct answer: B

Explanation: The slides explicitly say relational databases are fragmented/normalized while many NoSQL DBs
are aggregate-oriented.

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 7 - Examples of NoSQL databases

Figure: Original slide 7 (for reference)

Slide text (extracted):

4 Examples of NoSQL databases

:)‫الشرح بالعربي (المهم لالمتحان‬

Redis (Key-Value)، Neo4j ‫ و‬CouchDB (Document)، Riak ‫ و‬MongoDB :‫الساليد دي جدول أمثلة‬
.(Graph)، HBase (Columnar/Column-family)

‫؟‬Graph ‫؟ أو أيهم‬Document ‫ من دول‬DB ‫ أي‬:‫ األستاذ ممكن يسألك‬:‫نقطة امتحان‬

.‫ للمقارنة‬relational ‫ كمثال‬PostgreSQL ‫ الجدول فيه‬:‫خد بالك‬

English clarification (quick):

Know the mapping: MongoDB/CouchDB = document, Redis/Riak = key-value, Neo4j = graph, HBase = column-
family.

Mini-check (MCQ):

Which database is classified as a Graph database in the slide table?


 A) Redis
 B) Neo4j
 C) MongoDB
 D) HBase

Correct answer: B

Explanation: Neo4j is listed under the Graph genre.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 8 - Real-world pragmatics: big data + availability/security

Figure: Original slide 8 (for reference)

Slide text (extracted):

5 Databases in the real world:


pragmatics and performance
implications for database management.

 Will consider real world demands of databases & their


 The two main issues:
 high volumes of data
 keeping data available and secure

:)‫الشرح بالعربي (المهم لالمتحان‬

،‫ حجم بيانات عالي جًدا‬:‫ عندك ضغطين كبار‬.‫ نظري‬design ‫ مش بس‬،‫ في العالم الحقيقي‬:‫الساليد دي بتقول‬
.‫ وآمنة‬Available ‫والحفاظ على البيانات‬

.)fault tolerance( ‫الضغط ده بيخلي الشركات تفكر في توزيع البيانات وتحمل األعطال‬

English clarification (quick):

Real systems must handle high volumes and keep data available and secure.
Mini-check (MCQ):

The slides list two main real-world database issues as:

 A) Encryption and compression only


 B) High volumes of data and keeping data available/secure
 C) Only query syntax and parsing
 D) Only normalization and keys

Correct answer: B

Explanation: They explicitly state those two issues.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 9 - Scaling up vs scaling out, and sharding

Figure: Original slide 9 (for reference)

Slide text (extracted):

5 Databases in the real world:


pragmatics and performance
Increasing capacity for relational DBMSs:
distributing the database management features across several
computers.
redundancy.

 scaling up
 increasing the capacity of that computer ( one server), and then
 Expensive
 Fragile: if a server goes down, all data is lost.
 Scaling out
 many small servers distributing the data load between them with
 cheaper
 more robust
 Splitting one dataset across several servers is called sharding

:)‫الشرح بالعربي (المهم لالمتحان‬


.‫ على كذا جهاز‬features ‫ وأحياًنا توزع‬،)CPU/RAM/Storage :‫ أقوى‬server( ‫ تزود قوة جهاز واحد‬:Scaling up
.‫) ولو السيرفر وقع ممكن كل الخدمة تقع‬fragile( ‫ غالي وهش‬:‫المشكلة‬

.redundancy ‫) وتوزع الحمل والبيانات بينهم مع‬commodity( ‫ تجيب سيرفرات كتير صغيرة‬:Scaling out
.‫أرخص وأقوى ضد األعطال‬

.‫ دي كلمة األستاذ يحبها‬.‫ على أكتر من سيرفر‬dataset ‫ تقسيم‬:Sharding

English clarification (quick):

Scale up = bigger machine; scale out = many machines with distribution and redundancy.

Sharding = splitting one dataset across multiple servers.

Mini-check (MCQ):

In the slides, 'sharding' means:

 A) Encrypting database files


 B) Splitting one dataset across several servers
 C) Creating a primary key
 D) Converting SQL to NoSQL

Correct answer: B

Explanation: The slide defines sharding exactly as splitting a dataset across servers.

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 10 - Pros and cons of scaling out

Figure: Original slide 10 (for reference)

Slide text (extracted):

Adv. & disadv. Of


scaling out
Advantages:
same cost by buying many small ‘commodity’ computers and
disks, rather than a few large ones.
more easily distributed across the server farm.
exist on several servers, meaning that the loss of one machine
should not bring the entire operation to a grinding halt.
Disadvantages:
something, somewhere, will fail fairly often.

 More processing and storage capacity may be achieved for the


 It also offers the advantages of concurrency, as jobs can be
 Data will be resilient (flexible); replicated copies of data will
 More servers means more failures
 clusters should be designed with the presumption that

:)‫الشرح بالعربي (المهم لالمتحان‬


‫ أكتر بشراء أجهزة كتير صغيرة بدل‬processing/storage ‫ نفس التكلفة تقريًبا تقدر تجيب‬:scaling out ‫مميزات‬
.‫أجهزة قليلة ضخمة‬

.server farm ‫ تتوزع بسهولة على‬jobs ‫ ألن‬concurrency ‫كمان بيزود‬

.‫ لو واحد وقع مش الزم الدنيا تنهار‬:‫ على أكتر من سيرفر‬replication ‫ ألن فيه‬resilient ‫البيانات تبقى‬

.‫ فالزم تصمم وأنت متوقع إن حاجة هتفشل دايًما‬.‫ األعطال تزيد‬،‫ كل ما السيرفرات تزيد‬:‫العيب‬

English clarification (quick):

Scaling out improves capacity and resilience but increases failure frequency; design assuming failures.

Mini-check (MCQ):

A key disadvantage of scaling out mentioned is:

 A) Fewer failures because there are more servers


 B) More servers means more failures
 C) It is always more expensive than scaling up
 D) It removes the need for replication

Correct answer: B

Explanation: The slide literally states 'More servers means more failures.'

:Exam tip

.)more failures( ‫) والعيب‬cheap + resilient + concurrency( ‫ دايًما الميزة‬:scaling out ‫في أسئلة‬
Slide 11 - ACID vs BASE under distribution

Figure: Original slide 11 (for reference)

Slide text (extracted):

Implications of scaling out


including what is meant by a ‘transaction’.
subsets to remain available but unsynchronised, reconcile
the differences later.
(ACID) – part 12
changes to 
(BASE ) – part 17.

 Fundamental implications for how DBMSs operate,


 Pragmatic response to a network partition: allow the
 Atomicity, Consistency, Isolation, Durability
 Basically Available, Soft state, Eventual consistency

:)‫الشرح بالعربي (المهم لالمتحان‬

‫ أحياًنا الحل العملي إنك‬،network partition ‫ وتتعامل مع‬scaling out ‫ لما تعمل‬:‫دي من أهم ساليدات االمتحان‬
.‫) حتى لو البيانات مش متزامنة مؤقًتا‬available( ‫تسيب كل جزء من النظام شغال‬

.)‫مزامنة الحًقا‬/‫ (تسوية‬reconciliation later ‫بعد كده تعمل‬


BASE (Basically ‫ إلى‬ACID (Atomicity, Consistency, Isolation, Durability) ‫هنا بيظهر التحول من‬
.Available, Soft state, Eventual consistency)

.‫' مع الوقت‬eventually consistent' ‫ فوًر ا' تبقى‬consistent' ‫يعني بدل‬

English clarification (quick):

Network partitions push systems to choose availability and later reconciliation, leading to BASE/eventual
consistency rather than strict ACID.

Mini-check (MCQ):

BASE stands for:

 A) Binary Atomic Serial Execution


 B) Basically Available, Soft state, Eventual consistency
 C) Basic ACID Storage Engine
 D) Backup And Security Enforcement

Correct answer: B

Explanation: The slide spells out BASE as Basically Available, Soft state, Eventual consistency.

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 12 - Document databases: MongoDB (intro)

Figure: Original slide 12 (for reference)

Slide text (extracted):

Document databases: Mongo DB

:)‫الشرح بالعربي (المهم لالمتحان‬

.‫ كمثال‬MongoDB ‫ وبيستخدم‬،Document DBs ‫هنا بيبدأ جزء الـ‬

document ‫ بتخزنها كـ‬،)normalized( ‫ بدل ما تخزن بيانات الكيان موزعة على جداول كتير‬:document ‫فكرة‬
.nested structures (sub-documents, arrays) ‫واحد ممكن يحتوي‬

English clarification (quick):

Document DBs store aggregates as documents, often JSON-like.

Mini-check (MCQ):

MongoDB is primarily an example of which NoSQL category?

 A) Graph
 B) Document
 C) Column-family
 D) Relational

Correct answer: B

Explanation: The slides list MongoDB under Document databases.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 13 - Relational vs Document databases (structure)

Figure: Original slide 13 (for reference)

Slide text (extracted):

Comparing Rel. & Document DBs


Relational DBs:
1. A relational database comprises a set of tables.
2. Each table consists of a set of rows
3. Each row has the same set of fields
4. Within a table, field names must be unique
5. Field values must be atomic, although this may be NULL.
Documents DBs
1. A document database consists of a set of collections.
2. Each collection contains a set of documents
3. Each document contains a set of key–value pairs (also
referred to as fields)
4. Within a document, keys must be unique.
5. Key-values may be non-atomic and may contain empty (null)
values.

:)‫الشرح بالعربي (المهم لالمتحان‬


‫ داخل‬fields، field names unique ‫ نفس‬row ‫ وكل‬,Relational: Database = Tables, Table = Rows
.)NULL ‫ (أو‬atomic ‫ والقيم‬،‫الجدول‬

Document: Database = Collections, Collection = Documents, document = key-value pairs ،


.null ‫ وممكن‬non-atomic (lists, sub-documents) ‫ والقيم ممكن تبقى‬،document ‫ داخل الـ‬keys unique

.‫ مباشر‬MCQ ‫احفظ التحويل ده ألنه بيجي‬

English clarification (quick):

Relational: table/row/column. Document: collection/document/key.

Document values can be complex (non-atomic).

Mini-check (MCQ):

In a document database, the closest equivalent of a table is a:

 A) Row
 B) Collection
 C) Key
 D) Index

Correct answer: B

Explanation: The terminology mapping: Table/Relation -> Collection.

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 14 - Terminology mapping + example documents

Figure: Original slide 14 (for reference)

Slide text (extracted):

Relational vs. Document DB Terminologies


Relational DB Document DB
Database Database
Table / Relation Collection
Record / Row /Tuple Document
Field / Column name / Attribute Key
Field value / attribute value Key value
_id name address
1 John Highway37
{'_id': 1, 'name': 'John', 'address': 'Highway37'}
{'_id': 2, 'name': 'Peter', 'address': 'Lowstreet 27'}
2 Peter Lowstreet 27
{'_id': 3, 'name': 'Amy'}
3 Amy NULL
{'_id': 4, 'name': 'Hannah', 'address': 'Mountain 21'}
{'_id': 5, 'name': 'Michael', 'address': null }
4 Hannah Mountain 21
5 Michael NULL
Relational Table MongoDB Collection
:)‫الشرح بالعربي (المهم لالمتحان‬

Table -> Collection، Row/Tuple -> Document، Column name -> :‫ واضح‬mapping ‫الساليد دي بتعمل‬
.Key، Column value -> Key value

.‫ هتبقى جدول بأعمدة‬SQL ‫ في‬.id, name, address_ ‫ فيها‬documents :‫وبيوريك مثال بسيط‬

‫ (ده بيتشرح أكتر في ساليد‬keys ‫ يكون عنده نفس‬document ‫ مش شرط كل‬،document DB ‫ في‬:‫نقطة مهّمة‬
.)16

English clarification (quick):

Memorize the mapping and understand that documents may omit keys (e.g., address missing).

Mini-check (MCQ):

In the terminology table, a relational 'attribute' corresponds to a document DB:

 A) Key
 B) Document
 C) Collection
 D) Database

Correct answer: A

Explanation: Field/Column name/Attribute maps to Key.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 15 - Figure: document database concepts

Figure: Original slide 15 (for reference)

Slide text (extracted):

Figure 14.1 Document database concepts

:)‫الشرح بالعربي (المهم لالمتحان‬

.documents ‫ يحتوي‬collection ‫ وكل‬،collections ‫ يحتوي‬hierarchy: database ‫الشكل بيوضح‬

.)JSON ‫ جواه (زي‬nested documents ‫ ممكن يحتوي‬sub-documents: document ‫كمان فكرة‬

.naturally nested ‫ مناسب لحاالت البيانات اللي‬document DB ‫ده سبب إن‬

English clarification (quick):

Database -> collection -> documents; documents can contain embedded (sub)documents.

Mini-check (MCQ):

Which statement fits the figure?

 A) Collections contain tables


 B) A document may contain sub-documents
 C) Keys must be global across the entire database
 D) Documents cannot be nested

Correct answer: B

Explanation: The figure explicitly shows documents and sub-documents inside collections.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 16 - Key differences: schema-less + non-atomic values

Figure: Original slide 16 (for reference)

Slide text (extracted):

Key difference
inside the documents.
in a collection can have a different set of keys.
have complex structure, when the values are referred to
sub-documents.

 The key departure from the relational model is what is


 Document databases are schema-less: each document
 The values in the document need not be atomic: they can
 In MongoDB, all keys must be valid JavaScript strings.

:)‫الشرح بالعربي (المهم لالمتحان‬

keys ‫ ممكن يكون عنده‬collection ‫ في نفس‬document ‫ كل‬:document DB schema-less :‫دي أهم فروق‬
.‫مختلفة‬

.document ‫ جوه‬document ‫ أو‬list ‫ ممكن تكون‬:non-atomic ‫القيم‬

.)‫ (زي ما الساليد يقول‬JavaScript strings ‫ الزم تكون‬MongoDB: keys ‫في‬


.document ‫ مش‬relational ‫' ده‬each row has the same set of fields' ‫ لو لقيت اختيار بيقول‬:‫امتحان‬

English clarification (quick):

Schema-less collections allow varying keys; values can be nested structures.

Mini-check (MCQ):

Which is TRUE about document databases according to the slides?

 A) Every document in a collection must have identical keys


 B) Values must always be atomic
 C) Documents can have complex/nested values
 D) They require full normalization

Correct answer: C

Explanation: Slides say values need not be atomic and can contain sub-documents.

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 17 - Large document example (patient + prescriptions)

Figure: Original slide 17 (for reference)

Slide text (extracted):

Patient_id Patient_name doctor_id doctor_name date drug_code drug_name dosage duration


p001 Thronton d06 Gibson 15-May-2014 T02378 Tramadol 50 mg 3 x day As required
p001 Thronton d06 Gibson 15-May-2014 O17663 Omeprazole 40 mg 1 x day NULL
p001 Thronton d06 Gibson 23-May-2014 S33558 Simvastatin 40 mg 1 x day NULL
p001 Thronton d06 Gibson 15-Jun-2014 A12458 Amitriptyline 10 mg 5 x day As required
{'patient_id': 'p001',
List of
'patient_name': 'Thornton', MongoDB
subdocuments
'doctor_id': 'd06',
representation
'doctor_name': 'Gibson',
(as 1 document)
'prescribed_drugs': [
{'prescription_date': [Link](2014, 5, 15, 0, 0),
sub-sub-
'drug': {'code': 'T02378', 'drug_name': 'Tramadol'},
'dosage': '50mg 3 x day', documents
'duration': 'As required'},
{'prescription_date': [Link](2014, 5, 15, 0, 0),
This document is shown in a
'drug': {'code': 'O17663', 'drug_name': 'Omeprazole'},
'dosage': '40mg 1 x day'}, format similar to how it would
{'prescription_date': [Link](2014, 5, 23, 0, 0),
appear in the MongoDB console
'drug': {'code': 'S33558', 'drug_name': 'Simvastatin'},
(as JSON), and in the PyMongo
'dosage': '40mg 1 x day', 'duration': null },
{'prescription_date': [Link](2014, 6, 15, 0, 0), interface from Python to
'drug': {'code': 'A12458', 'drug_name': 'Amitriptyline'}, MongoDB.
'dosage': '10mg 5 x day',
'duration': '30 days'}
]
}

:)‫الشرح بالعربي (المهم لالمتحان‬

‫ كـ‬patient info + doctor info + prescribed_drugs ‫ فيه‬patient document :‫الساليد دي بتديك مثال واقعي‬
.sub-documents ‫ من‬list

‫ أنت مخزنهم‬،query ‫ في كل‬drug ‫ و‬prescription ‫ و‬patient ‫ بين‬join ‫ بدل ما تعمل‬:aggregate ‫ده مثال على‬
.‫ واحد‬document ‫مع بعض في‬

.‫ سريع لو غالًبا بتقرأ كل البيانات مع بعض‬read :‫الميزة‬

.‫) لو مكرر‬redundancy( ‫ كتير‬documents ‫ ممكن تحتاج تحدثه في‬، ‫ اتغير مثاًل‬doctor_name ‫ لو‬:‫العيب‬

English clarification (quick):

Embedded prescriptions avoid joins but can introduce redundancy and update challenges.

Mini-check (MCQ):

Storing prescriptions inside the patient document primarily reduces the need for:

 A) Indexes
 B) Joins across multiple tables/collections
 C) Primary keys
 D) Transactions in all cases

Correct answer: B

Explanation: Embedding related data in one document is a common way to reduce join operations.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 18 - Normalized vs un-normalized representation

Figure: Original slide 18 (for reference)

Slide text (extracted):

Un-
normalised
Normalised

:)‫الشرح بالعربي (المهم لالمتحان‬

)prescription ‫الدكتور مع كل‬/‫ (جدول كبير فيه تكرار بيانات المريض‬un-normalized ‫الصورة بتقارن شكل‬
.)drug + foreign keys ‫ و‬prescription ‫ و‬doctor ‫ و‬patient ‫ (جداول‬normalized ‫مقابل‬

.anomalies ‫ ونمنع‬redundancy ‫ عشان نقلل‬normalized ‫ إحنا بنفضل‬relational ‫في‬

‫ (خصوًصا‬performance ‫ عشان‬un-normalized/denormalized designs ‫ أحياًنا بتقبل‬document DB ‫في‬


.joins ‫) وتفادي‬reads

.intentional ‫ غالًبا‬NoSQL ‫' في‬denormalization' :‫دي فكرة امتحانية‬

English clarification (quick):

Relational designs normalize; document designs may denormalize for read performance.
Mini-check (MCQ):

Compared to normalized relational design, denormalizing into documents often aims to:

 A) Increase join cost


 B) Improve read performance by reducing joins
 C) Guarantee strict ACID across partitions
 D) Enforce atomic attributes only

Correct answer: B

Explanation: Denormalization trades redundancy for fewer joins and faster reads in many NoSQL use cases.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 19 - PyMongo representation (thinking in Python types)

Figure: Original slide 19 (for reference)

Slide text (extracted):

PyMongo
the MongoDB structures and native Python types.
initially in those terms.
patient_id, patient_name, doctor_id, and so on.
consists of a list of several sub-documents (themselves dicts).
contains a sub-document describing the drug.

 PyMongo converts many MongoDB data structures between


 You may therefore find it helpful to understand MongoDB
 PyMongo represents a document as a dict with several keys:
 Many keys have simple, atomic values – strings in this case.
 The prescribed_drugs key has a more complex value: it
 Each sub-document describes one prescription, which itself

:)‫الشرح بالعربي (المهم لالمتحان‬

.Python ‫ من‬MongoDB ‫ بيخليك تتعامل مع‬driver ‫ هو‬PyMongo

.‫ جوه بعض‬lists/dicts ‫ تبقى‬nested parts ‫ والـ‬،Python ‫ في‬dict ‫ لــ‬document ‫بيحول‬


.‫ بسرعة‬MongoDB ‫ هتفهم‬،dict/list ‫لو فهمت الداتا كـ‬

English clarification (quick):

PyMongo maps MongoDB documents to Python dicts; embedded structures become nested dict/list.

Mini-check (MCQ):

In PyMongo, a MongoDB document is commonly represented as:

 A) A Python dict
 B) A Python class only
 C) A CSV row
 D) A SQL table

Correct answer: A

Explanation: The slide says PyMongo represents a document as a dict with keys and values.

:Exam tip

.‫ مباشر‬MCQ ‫ركز على تعريفات المصطلحات ألنها بتطلع كـ‬


Slide 20 - SQL vs PyMongo: find(query, projection)

Figure: Original slide 20 (for reference)

Slide text (extracted):

Example: from Exercise 14.6


SQL PyMongo
select [Link](
patient_name, {'gender':'M','weight':{'$gt':75}},
date_of_birth ['patient_name', 'date_of_birth']
from patient )
where gender = 'M'
and weight > 75
find is a method that acts on a collection (patient, in this case). Its first argument is a query document that
specifies which documents in the collection will be returned. For a document to be returned, it must contain
the same keys as the query document (specified in the find) and those keys must have the specified values.
Various operators, such as '$gt' (‘greater than’), for conditions other than equality are provided (see
MongoDB: The Definitive Guide for descriptions of these operators).
In this case, the query document in the find statement specifies that the returned documents must have
gender and weight keys, the gender key must have a value of 'M', and the weight key must have a value
greater than 75.
The second, optional, argument is a list of the keys (and the associated values) to be included in the
returned documents. If this argument is missing, all keys of every matching document will be returned. This
is the same functionality as SQL’s select * from ....
:)‫الشرح بالعربي (المهم لالمتحان‬

.PyMongo find ‫ إلى‬SQL query ‫الساليد دي بتحول‬

SQL: select patient_name, date_of_birth from patient where gender='M' and weight>75

PyMongo: [Link]({'gender':'M','weight':{'$gt':75}}, ['patient_name','date_of_birth'])

.‫ المطلوبة وقيمها تطابق الشروط‬keys ‫ يحتوي‬document ‫ الزم الـ‬:query document ‫ هو‬parameter ‫أول‬

…lt, $gte, $in$ ‫ تانية زي‬operators ‫ وفيه‬.greater than ‫ معناها‬gt$

‫ لو مش موجود بيرجع كل الحقول (زي‬.‫ اللي عايز ترجعها‬keys ‫ بتحدد‬:projection ‫ اسمه‬parameter ‫ثاني‬
.)* select

English clarification (quick):

find() takes a query document; operators like $gt express conditions. Projection selects returned fields.

Mini-check (MCQ):

In PyMongo, the second argument to find() in the slide is used for:

 A) Sorting results
 B) Projection: selecting which keys/fields to return
 C) Creating an index
 D) Forcing ACID transactions

Correct answer: B

Explanation: The slide explains it as a list of keys to include in returned documents (projection).

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection
Slide 21 - Breakdown of find() components

Figure: Original slide 21 (for reference)

Slide text (extracted):

PyMongo's find method


collection
query
[Link](
document
{'gender':'M','weight':{
'$gt':75}},
>
['patient_name',
operator
'date_of_birth']
)
projection
Note: The projection is options. If this argument is missing, all keys
of every matching document will be returned. This is the same
functionality as SQL’s
select * from ....

:)‫الشرح بالعربي (المهم لالمتحان‬


.find: collection (patients)، query document، operator ($gt)، projection ‫الساليد األخيرة بتفكك الـ‬

:‫?' اإلجابة‬MCQ: 'If projection is omitted, what happens ‫ لو اتسأل‬.projection optional :‫مالحظة مهمة‬
.document matching ‫ لكل‬keys ‫يرجع كل‬

.‫دي نقطة سهلة بس بتجيب درجات‬

English clarification (quick):

[Link](query, projection). Projection optional; without it, return full matching documents.

Mini-check (MCQ):

If the projection argument is missing in find(), the result will include:

 A) Only _id by default


 B) All keys of every matching document
 C) No keys
 D) Only keys in the query

Correct answer: B

Explanation: The slide explicitly says projection is optional; if missing, all keys are returned (like SELECT *).

:Exam tip

schema-based/ schema- :‫ ركز على الكلمات المفتاحية‬،NoSQL ‫ و‬Relational ‫لو شفت سؤال بيقارن بين‬
.free, atomic/ non-atomic, ACID/BASE, scale-up/scale-out, sharding, projection

You might also like