This document provides an overview of schema design in MongoDB given different types of data relationships. It discusses modeling one-to-one, one-to-many, and many-to-many relationships using embedding, references, and hybrid approaches. Examples are given for a library management use case to model patrons, books, authors, and publishers and the tradeoffs of different schema designs depending on the growth and relationships of the data.
43. 4 ways of modeling one-to-many (there are more)
•
Embed the publisher
•
Use publisher as the "foreign key"
•
Use book as the "foreign key"
•
Hybrid
48. Where do you put the foreign key
•
Array of books inside of publisher
•
•
•
Makes sense when many means a handful of items
Useful when items have bounds on potential growth
Reference to a single publisher on each book
•
Useful when items have unbounded growth
49. Other Things To Model
•
Trees
•
Queues
•
Many-To-Many relationships