Week 6 L1 Flashcards
What is embedding and referencing ?
MongoDB does not support FK referencing of PK, there is no join operator.
Embedded object is implicitly joined
Referencing is controlled by application
What is one collection embedding ?
when embedded object not used independently of its parent object . Generally known as data aggregation.
Advantages of one collection embedding?
Provides performance advantage
Associated data is held in one document
data access by single command
What is single association embedding?
employee works on exactly one machine. Embedding one document in another. Embedded object no longer independent .
Advantages of Single Association embedding
everything in one place. makes updates very efficient
What is multiple association embedding
Multiple child objects embedded in one parent object. makes it difficult to insert child objects independent of parent.
When does multiple association embedding work well ?
Works well when the zero one or many relationships are few .
How to access document embedded fields?
Use dot notation
What is two collections referencing ?
Two collections used independently. requires two steps or join to retrieve related data from collections
application must control the referencing between documents
Advantages of two collections referencing
More flexible than embedded
What is single association referencing ?
Closest to the relational design solution
Employee works on exactly one machine
Allows objects to be independent
How do you reference?
update collection by add id reference into other object
How to reference across collection?
Use a loop with a cursor
What are alternatives to he join method ?
$lookup
What is multiple association referencing
0 one or many relationships.
Two collections with an array of references
Advantages of multiple association referencing
works well if many is limited to hundreds so doc size limit is not exceeded. this keeps fields independent so easy to search and update.
How to reference arrays ?
$in
What are more elaborate database designs?
partial redundancy : copy name/make into both employee and machine
Two-way referencing: both objects reference each other .
Two way embedding: wholesale redundancy
Read vs Write trade-offs
What is client side processing?
Processing on client side rather than database server side
What are manual refs ?
id field of one document copied in another document as reference
What are DB refs ? give examples operators
referencing across collections or databases , state database and collection and doc id. $ref, $id, $db
When would you use referencing in no sql ? give examples
Write once , read lots .
e.g. online shopping, social media posts
Advantages with NoSQL?
Write on massive scale
Reads very fast ( providing database is indexed and shared properly.
Storage is cheap and scalable.
Embedding data in single document instead of joining many tables makes retrieval faster
Disadvantages of NoSQL
No referential integrity
Few server side joins
not as good for normalised model.