Home Page Icon
Home Page
Table of Contents for
MongoDB Applied Design Patterns
Close
MongoDB Applied Design Patterns
by Rick Copeland
MongoDB Applied Design Patterns
Preface
Audience
Assumptions This Book Makes
Contents of This Book
Part I: Design Patterns
Part II: Use Cases
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
I. Design Patterns
1. To Embed or Reference
Relational Data Modeling and Normalization
What Is a Normal Form, Anyway?
So What’s the Problem?
Denormalizing for Performance
MongoDB: Who Needs Normalization, Anyway?
MongoDB Document Format
Embedding for Locality
Embedding for Atomicity and Isolation
Referencing for Flexibility
Referencing for Potentially High-Arity Relationships
Many-to-Many Relationships
Conclusion
2. Polymorphic Schemas
Polymorphic Schemas to Support Object-Oriented Programming
Polymorphic Schemas Enable Schema Evolution
Storage (In-)Efficiency of BSON
Object-Document Mappers
Polymorphic Schemas Support Semi-Structured Domain Data
Conclusion
3. Mimicking Transactional Behavior
The Relational Approach to Consistency
Compound Documents
Using Complex Updates
Optimistic Update with Compensation
Conclusion
II. Use Cases
4. Operational Intelligence
Storing Log Data
Solution Overview
Schema Design
Operations
Inserting a log record
Bulk inserts
Finding all events for a particular page
Aside: managing index size
Finding all the events for a particular date
Finding all events for a particular host/date
Rules of index design
Counting requests by day and page
Sharding Concerns
Limitations
Option 1: Shard by time
Option 2: Shard by a semi-random key
Option 3: Shard by an evenly distributed key in the data set
Option 4: Shard by combining a natural and synthetic key
Test with your own data
Managing Event Data Growth
Capped collections
TTL collections
Multiple collections, single database
Multiple databases
Pre-Aggregated Reports
Solution Overview
Schema Design
One document per page per day, flat documents
One document per page per day, hierarchical documents
Separate documents by granularity level
Operations
Log an event
Pre-allocate
Retrieving data for a real-time chart
Get data for a historical chart
Sharding Concerns
Hierarchical Aggregation
Solution Overview
Schema Design
MapReduce
Operations
Creating hourly views from event collections
Deriving day-level data
Weekly and monthly aggregation
Refactor map functions
Sharding Concerns
5. Ecommerce
Product Catalog
Solution Overview
Concrete-table inheritance
Single-table inheritance
Multiple-table inheritance
Entity attribute values
Avoid modeling product data altogether
The MongoDB answer
Operations
Find products sorted by percentage discount descending
Find albums by genre and sort by year produced
Find movies based on starring actor
Find movies with a particular word in the title
Conclusion: Index all the things!
Sharding Concerns
Scaling read performance without sharding
Category Hierarchy
Solution Overview
Schema Design
Operations
Read and display a category
Add a category to the hierarchy
Change the ancestry of a category
Rename a category
Sharding Concerns
Inventory Management
Solution Overview
Schema
Operations
Add an item to a shopping cart
Modifying the quantity in the cart
Checking out
Returning inventory from timed-out carts
Error handling
Sharding Concerns
6. Content Management Systems
Metadata and Asset Management
Solution Overview
Schema Design
GridFS
Operations
Create and edit content nodes
Upload a photo
Locate and render a node
Search for nodes by tag
Generate a feed of recently published blog articles
Sharding Concerns
Storing Comments
Solution Overview
Approach: One Document per Comment
Operation: Post a new comment
Operation: View paginated comments
Operation: Retrieve comments via direct links
Approach: Embedding All Comments
Operation: Post a new comment
Operation: View paginated comments
Operation: Retrieve a comment via direct links
Approach: Hybrid Schema Design
Operation: Post a new comment
Operation: View paginated comments
Operation: Retrieve a comment via direct links
Sharding Concerns
7. Online Advertising Networks
Solution Overview
Design 1: Basic Ad Serving
Schema Design
Operation: Choose an Ad to Serve
Operation: Make an Ad Campaign Inactive
Sharding Concerns
Design 2: Adding Frequency Capping
Schema Design
Operation: Choose an Ad to Serve
Sharding
Design 3: Keyword Targeting
Schema Design
Operation: Choose a Group of Ads to Serve
8. Social Networking
Solution Overview
Schema Design
Independent Collections
Dependent Collections
Operations
Viewing a News Feed or Wall Posts
Commenting on a Post
Creating a New Post
Maintaining the Social Graph
Sharding
9. Online Gaming
Solution Overview
Schema Design
Character Schema
Item Schema
Location Schema
Operations
Load Character Data from MongoDB
Extract Armor and Weapon Data for Display
Extract Character Attributes, Inventory, and Room Information for Display
Pick Up an Item from a Room
Remove an Item from a Container
Move the Character to a Different Room
Buy an Item
Sharding
Afterword
Where Do I Go from Here?
Index
About the Author
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
O'Reilly Strata Conference
Next
Next Chapter
Preface
MongoDB Applied Design Patterns
Rick Copeland
Beijing • Cambridge • Farnham • Köln • Sebastopol • Tokyo
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset