Home Page Icon
Home Page
Table of Contents for
V. Application Administration
Close
V. Application Administration
by Kristina Chodorow
MongoDB: The Definitive Guide, 2nd Edition
Foreword
Preface
How This Book Is Organized
Getting Started with MongoDB
Developing with MongoDB
Replication
Sharding
Application Administration
Server Administration
Appendixes
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
I. Introduction to MongoDB
1. Introduction
Ease of Use
Easy Scaling
Tons of Features…
…Without Sacrificing Speed
Let’s Get Started
2. Getting Started
Documents
Collections
Dynamic Schemas
Naming
Subcollections
Databases
Getting and Starting MongoDB
Introduction to the MongoDB Shell
Running the Shell
A MongoDB Client
Basic Operations with the Shell
Create
Read
Update
Delete
Data Types
Basic Data Types
Dates
Arrays
Embedded Documents
_id and ObjectIds
ObjectIds
Autogeneration of _id
Using the MongoDB Shell
Tips for Using the Shell
Running Scripts with the Shell
Creating a .mongorc.js
Customizing Your Prompt
Editing Complex Variables
Inconvenient Collection Names
3. Creating, Updating, and Deleting Documents
Inserting and Saving Documents
Bulk Insert
Insert Validation
Removing Documents
Remove Speed
Updating Documents
Document Replacement
Using Modifiers
Getting started with the “$set” modifier
Incrementing and decrementing
Array modifiers
Adding elements
Using arrays as sets
Removing elements
Positional array modifications
Modifier speed
Upserts
The save shell helper
Updating Multiple Documents
Returning Updated Documents
Setting a Write Concern
4. Querying
Introduction to find
Specifying Which Keys to Return
Limitations
Query Criteria
Query Conditionals
OR Queries
$not
Conditional Semantics
Type-Specific Queries
null
Regular Expressions
Querying Arrays
$all
$size
The $slice operator
Returning a matching array element
Array and range query interactions
Querying on Embedded Documents
$where Queries
Server-Side Scripting
Cursors
Limits, Skips, and Sorts
Comparison order
Avoiding Large Skips
Paginating results without skip
Finding a random document
Advanced Query Options
Getting Consistent Results
Immortal Cursors
Database Commands
How Commands Work
II. Designing Your Application
5. Indexing
Introduction to Indexing
Introduction to Compound Indexes
Using Compound Indexes
Choosing key directions
Using covered indexes
Implicit indexes
How $-Operators Use Indexes
Inefficient operators
Ranges
OR queries
Indexing Objects and Arrays
Indexing embedded docs
Indexing arrays
Multikey index implications
Index Cardinality
Using explain() and hint()
The Query Optimizer
When Not to Index
Types of Indexes
Unique Indexes
Compound unique indexes
Dropping duplicates
Sparse Indexes
Index Administration
Identifying Indexes
Changing Indexes
6. Special Index and Collection Types
Capped Collections
Creating Capped Collections
Sorting Au Naturel
Tailable Cursors
No-_id Collections
Time-To-Live Indexes
Full-Text Indexes
Search Syntax
Full-Text Search Optimization
Searching in Other Languages
Geospatial Indexing
Types of Geospatial Queries
Compound Geospatial Indexes
2D Indexes
Storing Files with GridFS
Getting Started with GridFS: mongofiles
Working with GridFS from the MongoDB Drivers
Under the Hood
7. Aggregation
The Aggregation Framework
Pipeline Operations
$match
$project
Pipeline expressions
Mathematical expressions
Date expressions
String expressions
Logical expressions
A projection example
$group
Grouping operators
Arithmetic operators
Extreme operators
Array operators
Grouping behavior
$unwind
$sort
$limit
$skip
Using Pipelines
MapReduce
Example 1: Finding All Keys in a Collection
Example 2: Categorizing Web Pages
MongoDB and MapReduce
The finalize function
Keeping output collections
MapReduce on a subset of documents
Using a scope
Getting more output
Aggregation Commands
count
distinct
group
Using a finalizer
Using a function as a key
8. Application Design
Normalization versus Denormalization
Examples of Data Representations
Cardinality
Friends, Followers, and Other Inconveniences
Dealing with the Wil Wheaton effect
Optimizations for Data Manipulation
Optimizing for Document Growth
Removing Old Data
Planning Out Databases and Collections
Managing Consistency
Migrating Schemas
When Not to Use MongoDB
III. Replication
9. Setting Up a Replica Set
Introduction to Replication
A One-Minute Test Setup
Configuring a Replica Set
rs Helper Functions
Networking Considerations
Changing Your Replica Set Configuration
How to Design a Set
How Elections Work
Member Configuration Options
Creating Election Arbiters
Use at most one arbiter
The downside to using an arbiter
Priority
Hidden
Slave Delay
Building Indexes
10. Components of a Replica Set
Syncing
Initial Sync
Handling Staleness
Heartbeats
Member States
Elections
Rollbacks
When Rollbacks Fail
11. Connecting to a Replica Set from Your Application
Client-to-Replica-Set Connection Behavior
Waiting for Replication on Writes
What Can Go Wrong?
Other Options for “w”
Custom Replication Guarantees
Guaranteeing One Server per Data Center
Guaranteeing a Majority of Nonhidden Members
Creating Other Guarantees
Sending Reads to Secondaries
Consistency Considerations
Load Considerations
Reasons to Read from Secondaries
12. Administration
Starting Members in Standalone Mode
Replica Set Configuration
Creating a Replica Set
Changing Set Members
Creating Larger Sets
Forcing Reconfiguration
Manipulating Member State
Turning Primaries into Secondaries
Preventing Elections
Using Maintenance Mode
Monitoring Replication
Getting the Status
Visualizing the Replication Graph
Replication Loops
Disabling Chaining
Calculating Lag
Resizing the Oplog
Restoring from a Delayed Secondary
Building Indexes
Replication on a Budget
How the Primary Tracks Lag
Master-Slave
Converting Master-Slave to a Replica Set
Mimicking Master-Slave Behavior with Replica Sets
IV. Sharding
13. Introduction to Sharding
Introduction to Sharding
Understanding the Components of a Cluster
A One-Minute Test Setup
14. Configuring Sharding
When to Shard
Starting the Servers
Config Servers
The mongos Processes
Adding a Shard from a Replica Set
Adding Capacity
Sharding Data
How MongoDB Tracks Cluster Data
Chunk Ranges
Splitting Chunks
The Balancer
15. Choosing a Shard Key
Taking Stock of Your Usage
Picturing Distributions
Ascending Shard Keys
Randomly Distributed Shard Keys
Location-Based Shard Keys
Shard Key Strategies
Hashed Shard Key
Hashed Shard Keys for GridFS
The Firehose Strategy
Multi-Hotspot
Shard Key Rules and Guidelines
Shard Key Limitations
Shard Key Cardinality
Controlling Data Distribution
Using a Cluster for Multiple Databases and Collections
Manual Sharding
16. Sharding Administration
Seeing the Current State
Getting a Summary with sh.status
Seeing Configuration Information
config.shards
config.databases
config.collections
config.chunks
config.changelog
config.tags
config.settings
Tracking Network Connections
Getting Connection Statistics
Limiting the Number of Connections
Server Administration
Adding Servers
Changing Servers in a Shard
Changing a shard from a standalone server to replica set
Removing a Shard
Changing Config Servers
Balancing Data
The Balancer
Changing Chunk Size
Moving Chunks
Jumbo Chunks
Distributing jumbo chunks
Preventing jumbo chunks
Refreshing Configurations
V. Application Administration
17. Seeing What Your Application Is Doing
Seeing the Current Operations
Finding Problematic Operations
Killing Operations
False Positives
Preventing Phantom Operations
Using the System Profiler
Calculating Sizes
Documents
Collections
Databases
Using mongotop and mongostat
18. Data Administration
Setting Up Authentication
Authentication Basics
Setting Up Authentication
How Authentication Works
Creating and Deleting Indexes
Creating an Index on a Standalone Server
Creating an Index on a Replica Set
Creating an Index on a Sharded Cluster
Removing Indexes
Beware of the OOM Killer
Preheating Data
Moving Databases into RAM
Moving Collections into RAM
Custom-Preheating
Compacting Data
Moving Collections
Preallocating Data Files
19. Durability
What Journaling Does
Planning Commit Batches
Setting Commit Intervals
Turning Off Journaling
Replacing Data Files
Repairing Data Files
The mongod.lock File
Sneaky Unclean Shutdowns
What MongoDB Does Not Guarantee
Checking for Corruption
Durability with Replication
VI. Server Administration
20. Starting and Stopping MongoDB
Starting from the Command Line
File-Based Configuration
Stopping MongoDB
Security
Data Encryption
SSL Connections
Logging
21. Monitoring MongoDB
Monitoring Memory Usage
Introduction to Computer Memory
Tracking Memory Usage
Tracking Page Faults
Minimizing Btree Misses
IO Wait
Tracking Background Flush Averages
Calculating the Working Set
Some Working Set Examples
Tracking Performance
Tracking Free Space
Monitoring Replication
22. Making Backups
Backing Up a Server
Filesystem Snapshot
Copying Data Files
Using mongodump
Moving collections and databases with mongodump and mongorestore
Administrative complications with unique indexes
Backing Up a Replica Set
Backing Up a Sharded Cluster
Backing Up and Restoring an Entire Cluster
Backing Up and Restoring a Single Shard
Creating Incremental Backups with mongooplog
23. Deploying MongoDB
Designing the System
Choosing a Storage Medium
An example from the wild
Recommended RAID Configurations
CPU
Choosing an Operating System
Swap Space
Filesystem
Virtualization
Turn Off Memory Overcommitting
Mystery Memory
Handling Network Disk IO Issues
Using Non-Networked Disks
Configuring System Settings
Turning Off NUMA
Setting a Sane Readahead
Disabling Hugepages
Choosing a Disk Scheduling Algorithm
Don’t Track Access Time
Modifying Limits
Configuring Your Network
System Housekeeping
Synchronizing Clocks
The OOM Killer
Turn Off Periodic Tasks
A. Installing MongoDB
Choosing a Version
Windows Install
Installing as a Service
POSIX (Linux, Mac OS X, and Solaris) Install
Installing from a Package Manager
B. MongoDB Internals
BSON
Wire Protocol
Data Files
Namespaces and Extents
Memory-Mapped Storage Engine
Index
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
16. Sharding Administration
Next
Next Chapter
17. Seeing What Your Application Is Doing
Part V. Application Administration
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