Please enable JavaScript.
Coggle requires JavaScript to display documents.
MongoDB Data Modeling Intro - Coggle Diagram
MongoDB Data Modeling Intro
Purpose
Pemodelan data mengacu pada pengorganisasian data dalam basis data dan hubungan antara entitas terkait
easier to manage data
queries more efficient
less memory and CPU
reduce cost
data access together should be stored together
Type of data relationship
one-to-many
entity in
one
set connected to
any number
entity in another set
many-to-many
any number
entities in one set connected to
any number
entites in another set
one-to-one
entity in
one
set connected to exactly
one
in another set
ways to model : embedding and referencing
Scale a data model
want to avoid unbounded doc (doc that grow infinitely) when use embedding
want optimum efficiency of :
query result time
memory usage
CPU usage
storage
when use embedding there are problem that array grows larger, so the solution is break data into multiple collections and use reference
Modeling data reltionship
Referencing
called linking or data normalization
no duplication data
smaller document
query from multiple document cost extra resource
save
_id field
of one document as link in another document
Embedding
avoid application join
provide better performance for read operation
allow update data in single write operation
also known nested document
often used when 1:M and N:M
store related data in single document
⚠️ warning :
can create large document
adding data without limit create unbounded document
may exceed maximum BSON : 16 mb
Difference
Embedding :
✅ single query to retrieve data
✅ single operation to update/delete data
❗data duplication
❗large document
Referencing :
✅ no duplication
✅ smaller documents
❗need to join data from multiple doc