You are previewing The Definitive Guide to MongoDB: A complete guide to dealing with Big Data using MongoDB, Third Edition.
O'Reilly logo
The Definitive Guide to MongoDB: A complete guide to dealing with Big Data using MongoDB, Third Edition

Book Description

The Definitive Guide to MongoDB, Third Edition, is updated for MongoDB 3 and includes all of the latest MongoDB features, including the aggregation framework introduced in version 2.2 and hashed indexes in version 2.4. The Third Edition also now includes Node.js along with Python.

MongoDB is the most popular of the "Big Data" NoSQL database technologies, and it's still growing. David Hows from 10gen, along with experienced MongoDB authors Peter Membrey and Eelco Plugge, provide their expertise and experience in teaching you everything you need to know to become a MongoDB pro.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Authors
  8. About the Technical Reviewer
  9. About the Contributor
  10. Acknowledgments
  11. Introduction
  12. Chapter 1 : Introduction to MongoDB
    1. Reviewing the MongoDB Philosophy
      1. Using the Right Tool for the Right Job
      2. Lacking Innate Support for Transactions
      3. JSON and MongoDB
      4. Adopting a Nonrelational Approach
      5. Opting for Performance vs. Features
      6. Running the Database Anywhere
    2. Fitting Everything Together
      1. Generating or Creating a Key
      2. Using Keys and Values
      3. Implementing Collections
      4. Understanding Databases
    3. Reviewing the Feature List
      1. WiredTiger
      2. Using Document-Oriented Storage (BSON)
      3. Supporting Dynamic Queries
      4. Indexing Your Documents
      5. Leveraging Geospatial Indexes
      6. Profiling Queries
      7. Updating Information In Place (Memory Mapped Database Only)
      8. Storing Binary Data
      9. Replicating Data
      10. Implementing Sharding
      11. Using Map and Reduce Functions
      12. The Aggregation Framework
    4. Getting Help
      1. Visiting the Website
      2. Cutting and Pasting MongoDB Code
      3. Finding Solutions on Google Groups
      4. Finding Solutions on Stack Overflow
      5. Leveraging the JIRA Tracking System
      6. Chatting with the MongoDB Developers
    5. Summary
  13. Chapter 2 : Installing MongoDB
    1. Choosing Your Version
      1. Understanding the Version Numbers
    2. Installing MongoDB on Your System
      1. Installing MongoDB under Linux
      2. Installing MongoDB under Windows
    3. Running MongoDB
      1. Prerequisites
      2. Surveying the Installation Layout
      3. Using the MongoDB Shell
    4. Installing Additional Drivers
      1. Installing the PHP Driver
      2. Confirming That Your PHP Installation Works
      3. Installing the Python Driver
      4. Confirming That Your PyMongo Installation Works
    5. Summary
  14. Chapter 3 : The Data Model
    1. Designing the Database
      1. Drilling Down on Collections
      2. Using Documents
      3. Creating the _id Field
    2. Building Indexes
      1. Impacting Performance with Indexes
    3. Implementing Geospatial Indexing
      1. Querying Geospatial Information
    4. Pluggable Storage Engines
    5. Using MongoDB in the Real World
    6. Summary
  15. Chapter 4 : Working with Data
    1. Navigating Your Databases
      1. Viewing Available Databases and Collections
    2. Inserting Data into Collections
    3. Querying for Data
      1. Using the Dot Notation
      2. Using the Sort, Limit, and Skip Functions
      3. Working with Capped Collections, Natural Order, and $natural
      4. Retrieving a Single Document
      5. Using the Aggregation Commands
      6. Working with Conditional Operators
      7. Leveraging Regular Expressions
    4. Updating Data
      1. Updating with update()
      2. Implementing an Upsert with the save() Command
      3. Updating Information Automatically
      4. Removing Elements from an Array
      5. Specifying the Position of a Matched Array
      6. Atomic Operations
      7. Modifying and Returning a Document Atomically
    5. Processing Data in Bulk
      1. Executing Bulk Operations
      2. Evaluating the Output
    6. Renaming a Collection
    7. Deleting Data
    8. Referencing a Database
      1. Referencing Data Manually
      2. Referencing Data with DBRef
    9. Implementing Index-Related Functions
      1. Surveying Index-Related Commands
    10. Summary
  16. Chapter 5 : GridFS
    1. Filling in Some Background
    2. Working with GridFS
    3. Getting Started with the Command-Line Tools
      1. Using the _id Key
      2. Working with Filenames
      3. The File’s Length
      4. Working with Chunk Sizes
      5. Tracking the Upload Date
      6. Hashing Your Files
    4. Looking Under MongoDB’s Hood
      1. Using the search Command
      2. Deleting
      3. Retrieving Files from MongoDB
      4. Summing Up mongofiles
    5. Exploiting the Power of Python
      1. Connecting to the Database
      2. Accessing the Words
    6. Putting Files into MongoDB
    7. Retrieving Files from GridFS
    8. Deleting Files
    9. Summary
  17. Chapter 6 : PHP and MongoDB
    1. Comparing Documents in MongoDB and PHP
    2. MongoDB Classes
      1. Connecting and Disconnecting
      2. Inserting Data
    3. Listing Your Data
      1. Returning a Single Document
      2. Listing All Documents
    4. Using Query Operators
      1. Querying for Specific Information
      2. Sorting, Limiting, and Skipping Items
      3. Counting the Number of Matching Results
      4. Grouping Data with the Aggregation Framework
      5. Specifying the Index with Hint
      6. Refining Queries with Conditional Operators
      7. Determining Whether a Field Has a Value
      8. Regular Expressions
    5. Modifying Data with PHP
      1. Updating via update()
      2. Saving Time with Update Operators
      3. Upserting Data with save()
      4. Modifying a Document Atomically
    6. Processing Data in Bulk
      1. Executing Bulk Operations
      2. Evaluating the Output
    7. Deleting Data
    8. DBRef
      1. Retrieving the Information
    9. GridFS and the PHP Driver
      1. Storing Files
      2. Adding More Metadata to Stored Files
      3. Retrieving Files
      4. Deleting Data
    10. Summary
  18. Chapter 7 : Python and MongoDB
    1. Working with Documents in Python
    2. Using PyMongo Modules
    3. Connecting and Disconnecting
    4. Inserting Data
    5. Finding Your Data
      1. Finding a Single Document
      2. Finding Multiple Documents
      3. Using Dot Notation
      4. Returning Fields
      5. Simplifying Queries with sort(), limit(), and skip()
      6. Aggregating Queries
      7. Specifying an Index with hint()
      8. Refining Queries with Conditional Operators
      9. Conducting Searches with Regular Expressions
    6. Modifying the Data
      1. Updating Your Data
      2. Modifier Operators
      3. Replacing Documents with replace_one()
      4. Modifying a Document Atomically
      5. Putting the Parameters to Work
    7. Processing Data in Bulk
      1. Executing Bulk Operations
    8. Deleting Data
    9. Creating a Link Between Two Documents
      1. Retrieving the Information
    10. Summary
  19. Chapter 8 : Advanced Queries
    1. Text Search
      1. Text Search Costs and Limitations
      2. Using Text Search
      3. Text Indexes in Other Languages
      4. Compound Indexing with Text Indexes
    2. The Aggregation Framework
      1. Using the $group Command
      2. Using the $limit Operator
      3. Using the $match Operator
      4. Using the $sort Operator
      5. Using the $unwind Operator
      6. Using the $skip Operator
      7. Using the $out Operator
      8. Using the $lookup Operator
    3. MapReduce
      1. How MapReduce Works
      2. Setting Up Testing Documents
      3. Working with Map Functions
      4. Advanced MapReduce
      5. Debugging MapReduce
    4. Summary
  20. Chapter 9 : Database Administration
    1. Using Administrative Tools
      1. mongo, the MongoDB Console
      2. Using Third-Party Administration Tools
    2. Backing Up the MongoDB Server
      1. Creating a Backup 101
      2. Backing Up a Single Database
      3. Backing Up a Single Collection
    3. Digging Deeper into Backups
    4. Restoring Individual Databases or Collections
      1. Restoring a Single Database
      2. Restoring a Single Collection
    5. Automating Backups
      1. Using a Local Datastore
      2. Using a Remote (Cloud-Based) Datastore
    6. Backing Up Large Databases
      1. Using a Hidden Secondary Server for Backups
      2. Creating Snapshots with a Journaling Filesystem
      3. Disk Layout to Use with Volume Managers
    7. Importing Data into MongoDB
    8. Exporting Data from MongoDB
    9. Securing Your Data by Restricting Access to a MongoDB Server
    10. Protecting Your Server with Authentication
      1. Adding an Admin User
      2. Enabling Authentication
      3. Authenticating in the mongo Console
      4. MongoDB User Roles
      5. Changing a User’s Credentials
      6. Adding a Read-Only User
      7. Deleting a User
      8. Using Authenticated Connections in a PHP Application
    11. Managing Servers
      1. Starting a Server
      2. Getting the Server’s Version
      3. Getting the Server’s Status
      4. Shutting Down a Server
    12. Using MongoDB Log Files
    13. Validating and Repairing Your Data
      1. Repairing a Server
      2. Validating a Single Collection
      3. Repairing Collection Validation Faults
      4. Repairing a Collection’s Data Files
      5. Compacting a Collection’s Data Files
    14. Upgrading MongoDB
      1. Rolling Upgrade of MongoDB
    15. Monitoring MongoDB
    16. Using MongoDB Cloud Manager
    17. Summary
  21. Chapter 10 : Optimization
    1. Optimizing Your Server Hardware for Performance
    2. Understanding MongoDB’s Storage Engines
    3. Understanding MongoDB Memory Use Under MMAPv1
      1. Understanding Working Set Size in MMAPv1
    4. Understanding MongoDB Memory Use Under WiredTiger
      1. Compression in WiredTiger
      2. Choosing the Right Database Server Hardware
    5. Evaluating Query Performance
      1. The MongoDB Profiler
      2. Analyzing a Specific Query with explain()
      3. Using the Profiler and explain() to Optimize a Query
    6. Managing Indexes
      1. Listing Indexes
      2. Creating a Simple Index
      3. Creating a Compound Index
    7. Three-Step Compound Indexes By A. Jesse Jiryu Davis
      1. The Setup
      2. Range Query
      3. Equality Plus Range Query
      4. Digression: How MongoDB Chooses an Index
      5. Equality, Range Query, and Sort
      6. Final Method
    8. Specifying Index Options
      1. Creating an Index in the Background with {background:true}
      2. Creating an Index with a Unique Key {unique:true}
      3. Creating Sparse Indexes with {sparse:true}
      4. Creating Partial Indexes
      5. TTL Indexes
      6. Text Search Indexes
      7. Dropping an Index
      8. Reindexing a Collection
    9. Using hint( ) to Force Using a Specific Index
    10. Using Index Filters
    11. Optimizing the Storage of Small Objects
    12. Summary
  22. Chapter 11 : Replication
    1. Spelling Out MongoDB’s Replication Goals
      1. Improving Scalability
      2. Improving Durability/Reliability
      3. Providing Isolation
    2. Replication Fundamentals
      1. What Is a Primary?
      2. What Is a Secondary?
      3. What Is an Arbiter?
    3. Drilling Down on the Oplog
    4. Implementing a Replica Set
      1. Creating a Replica Set
      2. Getting a Replica Set Member Up and Running
      3. Adding a Server to a Replica Set
      4. Adding an Arbiter
      5. Replica Set Chaining
      6. Managing Replica Sets
      7. Configuring the Options for Replica Set Members
      8. Connecting to a Replica Set from Your Application
    5. Read Concern
    6. Summary
  23. Chapter 12 : Sharding
    1. Exploring the Need for Sharding
    2. Partitioning Horizontal and Vertical Data
      1. Partitioning Data Vertically
      2. Partitioning Data Horizontally
    3. Analyzing a Simple Sharding Scenario
    4. Implementing Sharding with MongoDB
      1. Setting Up a Sharding Configuration
      2. Determining How You’re Connected
      3. Listing the Status of a Sharded Cluster
      4. Using Replica Sets to Implement Shards
    5. The Balancer
    6. Hashed Shard Keys
    7. Tag Sharding
    8. Adding More Config Servers
    9. Summary
  24. Index