MongoDB and PHP

Book description

What would happen if you optimized a data store for the operations application developers actually use? You’d arrive at MongoDB, the reliable document-oriented database. With this concise guide, you’ll learn how to build elegant database applications with MongoDB and PHP.

Written by the Chief Solutions Architect at 10gen—the company that develops and supports this open source database—this book takes you through MongoDB basics such as queries, read-write operations, and administration, and then dives into MapReduce, sharding, and other advanced topics. Get out of the relational database rut, and take advantage of a high-performing system optimized for operations and scale.

  • Learn step-by-step the tools you need to build PHP applications with MongoDB
  • Perform Create, Read, Update, and Delete (CRUD) operations, and learn how to perform queries to retrieve data
  • Administer your database, and access and manipulate data with the MongoDB Shell
  • Use functions to work with sets, arrays, and multiple documents to perform synchronous, asynchronous, and atomic operations
  • Discover PHP’s community tools and libraries, and why they’re valuable
  • Work with regular expressions, aggregation, MapReduce, replication, and sharding

Publisher resources

View/Submit Errata

Table of contents

  1. MongoDB and PHP
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. Safari® Books Online
    4. How to Contact Us
  4. 1. Why Mongo?
    1. The Problem of Objects and Relational Data Structures
    2. The Problem with ORMs
      1. ORMs Are Hairy and Complex
      2. ORMs Aren’t Performant
      3. ORMs Neutered SQL
      4. Complicated Architecture
      5. PHP Is Mostly CRUD
    3. MongoDB, Optimized for Operation
      1. MongoDB Is a Document Database
      2. Document == Array
        1. Databases
        2. Collections
        3. Documents
      3. MongoDB Is Optimized for CRUD Operations
      4. Optimal Interface for Developers
      5. Optimal Performance
      6. Optimal Simplicity
      7. The Value of Consistency
  5. 2. PHP, MongoDB, and You
    1. Installing the Driver on Linux or MacOS X
      1. Checking for the Driver
      2. Installing the Driver
      3. Upgrading the Driver
    2. Installing the Driver on Windows
    3. Connecting to a Database
      1. Connecting to a MongoDB Database Server
      2. Selecting a Database
    4. The Basics (CRUD Operations)
      1. Creating/Selecting a Collection
      2. Creating a Document
        1. Important Details about Updating
        2. About Consistency
        3. About fsync
      3. Primary Keys and ObjectIds
        1. About Primary Keys
      4. Reading a Document
        1. About ObjectIds
        2. Retrieving Select Values
      5. Updating a Document
        1. Changing a Value
        2. Adding a Value
        3. Appending a Value to an Array
        4. Upsert and Multiple
      6. Saving a Document
      7. Deleting a Document
    5. The MongoDB Shell
      1. mongo
      2. Using the Shell
        1. Shell Is JavaScript
      3. Administrative Commands
    6. Working with Sets
      1. Querying Sets
      2. Finding (Querying) Data in MongoDB
      3. Pagination with the Cursor
      4. Ranges
      5. Working with Arrays
        1. Finding a Value in an Array
        2. $in
        3. $nin
        4. $all
        5. Matching Entire Arrays
        6. $slice
        7. $size
        8. $elemMatch
        9. Using Dot Notation
      6. Conditionals
      7. Working with Multiple Documents
        1. Updating Multiple Records
        2. Deleting Multiple Records
    7. Working with Indexes
      1. Setting Indexes
      2. Index Order
      3. About Indexes
      4. Compound Indexes
      5. Indexing Arrays
      6. Indexes and Memory
    8. Database References
      1. References Are Not Foreign Keys
      2. When to Use References or Reference versus Embed
      3. How to Create References
        1. Creating Manual References
        2. Creating DBRefs
      4. How to Access DBRefs
    9. Dates and Times
  6. 3. Advanced MongoDB
    1. Regular Expressions
      1. Creating a MongoDB Regular Expression
      2. Regular Expressions and Indexes
    2. Aggregation Commands
      1. The Distinct Command
      2. The Group Command
        1. Group Parameters
        2. Group Examples
      3. MapReduce
        1. Overview
    3. findAndModify
    4. GridFS
      1. What Is GridFS?
      2. Using GridFS
      3. Mongofiles
    5. Replication
      1. High Availability
      2. Why Three Nodes?
      3. Really Easy Configuration
      4. Checking the Replica Set Status
    6. Sharding
    7. Gotchas
      1. The $ Problem
      2. The Array != Array Problem
      3. Request Injection Attacks
  7. 4. PHP Libraries and Tools
    1. Object Document Mappers (ODM)
      1. Doctrine MongoDB ODM
      2. Active Mongo
      3. Mandango
    2. Tools
      1. MongoQueue
      2. Genghis
      3. RockMongo
    3. Frameworks
      1. Symfony2
      2. Lithium
      3. Zend
      4. Fuel
      5. FatFree Framework
  8. 5. Conclusion
  9. About the Author
  10. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  11. Copyright

Product information

  • Title: MongoDB and PHP
  • Author(s): Steve Francia
  • Release date: January 2012
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449324841