MongoDB: The Definitive Guide

Book description

How does MongoDB help you manage a huMONGOus amount of data collected through your web application? With this authoritative introduction, you'll learn the many advantages of using document-oriented databases, and discover why MongoDB is a reliable, high-performance system that allows for almost infinite horizontal scalability.

Written by engineers from 10gen, the company that develops and supports this open source database, MongoDB: The Definitive Guide provides guidance for database developers, advanced configuration for system administrators, and an overview of the concepts and use cases for other people on your project. Learn how easy it is to handle data as self-contained JSON-style documents, rather than as records in a relational database.

  • Explore ways that document-oriented storage will work for your project
  • Learn how MongoDB’s schema-free data model handles documents, collections, and multiple databases
  • Execute basic write operations, and create complex queries to find data with any criteria
  • Use indexes, aggregation tools, and other advanced query techniques
  • Learn about monitoring, security and authentication, backup and repair, and more
  • Set up master-slave and automatic failover replication in MongoDB
  • Use sharding to scale MongoDB horizontally, and learn how it impacts applications
  • Get example applications written in Java, PHP, Python, and Ruby

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. How This Book Is Organized
      1. Getting Up to Speed with MongoDB
      2. Developing with MongoDB
      3. Advanced Usage
      4. Administration
      5. Developing Applications with MongoDB
      6. Appendixes
    2. Conventions Used in This Book
    3. Using Code Examples
    4. Safari® Books Online
    5. How to Contact Us
    6. Acknowledgments
      1. Acknowledgments from Kristina
      2. Acknowledgments from Michael
  3. 1. Introduction
    1. A Rich Data Model
    2. Easy Scaling
    3. Tons of Features…
    4. …Without Sacrificing Speed
    5. Simple Administration
    6. But Wait, That’s Not All…
  4. 2. Getting Started
    1. Documents
    2. Collections
      1. Schema-Free
      2. Naming
        1. Subcollections
    3. Databases
    4. Getting and Starting MongoDB
    5. MongoDB Shell
      1. Running the Shell
      2. A MongoDB Client
      3. Basic Operations with the Shell
        1. Create
        2. Read
        3. Update
        4. Delete
      4. Tips for Using the Shell
        1. Inconvenient collection names
    6. Data Types
      1. Basic Data Types
      2. Numbers
      3. Dates
      4. Arrays
      5. Embedded Documents
      6. _id and ObjectIds
        1. ObjectIds
        2. Autogeneration of _id
  5. 3. Creating, Updating, and Deleting Documents
    1. Inserting and Saving Documents
      1. Batch Insert
      2. Inserts: Internals and Implications
    2. Removing Documents
      1. Remove Speed
    3. Updating Documents
      1. Document Replacement
      2. Using Modifiers
        1. Getting started with the “$set” modifier
        2. Incrementing and decrementing
        3. Array modifiers
        4. Positional array modifications
        5. Modifier speed
      3. Upserts
        1. The save Shell Helper
      4. Updating Multiple Documents
      5. Returning Updated Documents
    4. The Fastest Write This Side of Mississippi
      1. Safe Operations
      2. Catching “Normal” Errors
    5. Requests and Connections
  6. 4. Querying
    1. Introduction to find
      1. Specifying Which Keys to Return
      2. Limitations
    2. Query Criteria
      1. Query Conditionals
      2. OR Queries
      3. $not
      4. Rules for Conditionals
    3. Type-Specific Queries
      1. null
      2. Regular Expressions
      3. Querying Arrays
        1. $all
        2. $size
        3. The $slice operator
      4. Querying on Embedded Documents
    4. $where Queries
    5. Cursors
      1. Limits, Skips, and Sorts
        1. Comparison order
      2. Avoiding Large Skips
        1. Paginating results without skip
        2. Finding a random document
      3. Advanced Query Options
      4. Getting Consistent Results
    6. Cursor Internals
  7. 5. Indexing
    1. Introduction to Indexing
      1. Scaling Indexes
      2. Indexing Keys in Embedded Documents
      3. Indexing for Sorts
      4. Uniquely Identifying Indexes
    2. Unique Indexes
      1. Dropping Duplicates
      2. Compound Unique Indexes
    3. Using explain and hint
    4. Index Administration
      1. Changing Indexes
    5. Geospatial Indexing
      1. Compound Geospatial Indexes
      2. The Earth Is Not a 2D Plane
  8. 6. Aggregation
    1. count
    2. distinct
    3. group
      1. Using a Finalizer
      2. Using a Function as a Key
    4. MapReduce
      1. Example 1: Finding All Keys in a Collection
      2. Example 2: Categorizing Web Pages
      3. MongoDB and MapReduce
        1. The finalize function
        2. Keeping output collections
        3. MapReduce on a subset of documents
        4. Using a scope
        5. Getting more output
  9. 7. Advanced Topics
    1. Database Commands
      1. How Commands Work
      2. Command Reference
    2. Capped Collections
      1. Properties and Use Cases
      2. Creating Capped Collections
      3. Sorting Au Naturel
      4. Tailable Cursors
    3. GridFS: Storing Files
      1. Getting Started with GridFS: mongofiles
      2. Working with GridFS from the MongoDB Drivers
      3. Under the Hood
    4. Server-Side Scripting
      1. db.eval
      2. Stored JavaScript
      3. Security
    5. Database References
      1. What Is a DBRef?
      2. Example Schema
      3. Driver Support for DBRefs
      4. When Should DBRefs Be Used?
  10. 8. Administration
    1. Starting and Stopping MongoDB
      1. Starting from the Command Line
      2. File-Based Configuration
      3. Stopping MongoDB
    2. Monitoring
      1. Using the Admin Interface
      2. serverStatus
      3. mongostat
      4. Third-Party Plug-Ins
    3. Security and Authentication
      1. Authentication Basics
      2. How Authentication Works
      3. Other Security Considerations
    4. Backup and Repair
      1. Data File Backup
      2. mongodump and mongorestore
      3. fsync and Lock
      4. Slave Backups
      5. Repair
  11. 9. Replication
    1. Master-Slave Replication
      1. Options
      2. Adding and Removing Sources
    2. Replica Sets
      1. Initializing a Set
      2. Nodes in a Replica Set
      3. Failover and Primary Election
    3. Performing Operations on a Slave
      1. Read Scaling
      2. Using Slaves for Data Processing
    4. How It Works
      1. The Oplog
      2. Syncing
      3. Replication State and the Local Database
      4. Blocking for Replication
    5. Administration
      1. Diagnostics
      2. Changing the Oplog Size
      3. Replication with Authentication
  12. 10. Sharding
    1. Introduction to Sharding
    2. Autosharding in MongoDB
      1. When to Shard
    3. The Key to Sharding: Shard Keys
      1. Sharding an Existing Collection
      2. Incrementing Shard Keys Versus Random Shard Keys
      3. How Shard Keys Affect Operations
    4. Setting Up Sharding
      1. Starting the Servers
        1. Adding a shard
      2. Sharding Data
    5. Production Configuration
      1. A Robust Config
      2. Many mongos
      3. A Sturdy Shard
      4. Physical Servers
    6. Sharding Administration
      1. config Collections
        1. Shards
        2. Databases
        3. Chunks
      2. Sharding Commands
        1. Getting a summary
        2. Removing a shard
  13. 11. Example Applications
    1. Chemical Search Engine: Java
      1. Installing the Java Driver
      2. Using the Java Driver
      3. Schema Design
      4. Writing This in Java
      5. Issues
    2. News Aggregator: PHP
      1. Installing the PHP Driver
        1. Windows install
        2. Mac OS X Install
        3. Linux and Unix install
      2. Using the PHP Driver
      3. Designing the News Aggregator
      4. Trees of Comments
      5. Voting
    3. Custom Submission Forms: Ruby
      1. Installing the Ruby Driver
      2. Using the Ruby Driver
      3. Custom Form Submission
      4. Ruby Object Mappers and Using MongoDB with Rails
    4. Real-Time Analytics: Python
      1. Installing PyMongo
      2. Using PyMongo
      3. MongoDB for Real-Time Analytics
      4. Schema
      5. Handling a Request
      6. Using Analytics Data
      7. Other Considerations
  14. A. Installing MongoDB
    1. Choosing a Version
    2. Windows Install
      1. Installing as a Service
    3. POSIX (Linux, Mac OS X, and Solaris) Install
      1. Installing from a Package Manager
  15. B. mongo: The Shell
    1. Shell Utilities
  16. C. MongoDB Internals
    1. BSON
    2. Wire Protocol
    3. Data Files
    4. Namespaces and Extents
    5. Memory-Mapped Storage Engine
  17. Index
  18. About the Authors
  19. Colophon
  20. Copyright

Product information

  • Title: MongoDB: The Definitive Guide
  • Author(s): Kristina Chodorow, Michael Dirolf
  • Release date: September 2010
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449381561