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