CouchDB: The Definitive Guide

Book description

Three of CouchDB's creators show you how to use this document-oriented database as a standalone application framework or with high-volume, distributed applications. With its simple model for storing, processing, and accessing data, CouchDB is ideal for web applications that handle huge amounts of loosely structured data. That alone would stretch the limits of a relational database, yet CouchDB offers an open source solution that's reliable, scales easily, and responds quickly.

CouchDB works with self-contained data that has loose or ad-hoc connections. It's a model that fits many real-world items, such as contacts, invoices, and receipts, but you'll discover that this database can easily handle data of any kind. With this book, you'll learn how to work with CouchDB through its RESTful web interface, and become familiar with key features such as simple document CRUD (create, read, update, delete), advanced MapReduce, deployment tuning, and more.

  • Understand the basics of document-oriented storage and manipulation
  • Interact with CouchDB entirely though HTTP using its RESTful interface
  • Model data as self-contained JSON documents
  • Handle evolving data schemas naturally
  • Query and aggregate data in CouchDB using MapReduce views
  • Replicate data between nodes
  • Tune CouchDB for increased performance and reliability

Publisher resources

View/Submit Errata

Table of contents

  1. CouchDB: The Definitive Guide
  2. Dedication
  3. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  4. Foreword
  5. Preface
    1. Using Code Examples
    2. Conventions Used in This Book
    3. Safari® Books Online
    4. How to Contact Us
    5. Acknowledgments
      1. J. Chris
      2. Jan
      3. Noah
  6. I. Introduction
    1. 1. Why CouchDB?
      1. Relax
      2. A Different Way to Model Your Data
      3. A Better Fit for Common Applications
        1. Self-Contained Data
        2. Syntax and Semantics
      4. Building Blocks for Larger Systems
        1. CouchDB Replication
      5. Local Data Is King
      6. Wrapping Up
    2. 2. Eventual Consistency
      1. Working with the Grain
      2. The CAP Theorem
      3. Local Consistency
        1. The Key to Your Data
        2. No Locking
        3. Validation
      4. Distributed Consistency
        1. Incremental Replication
        2. Case Study
      5. Wrapping Up
    3. 3. Getting Started
      1. All Systems Are Go!
      2. Welcome to Futon
      3. Your First Database and Document
      4. Running a Query Using MapReduce
      5. Triggering Replication
      6. Wrapping Up
    4. 4. The Core API
      1. Server
      2. Databases
      3. Documents
        1. Revisions
        2. Documents in Detail
          1. Attachments
      4. Replication
      5. Wrapping Up
  7. II. Developing with CouchDB
    1. 5. Design Documents
      1. Document Modeling
      2. The Query Server
      3. Applications Are Documents
      4. A Basic Design Document
      5. Looking to the Future
    2. 6. Finding Your Data with Views
      1. What Is a View?
      2. Efficient Lookups
        1. Find One
        2. Find Many
        3. Reversed Results
      3. The View to Get Comments for Posts
      4. Reduce/Rereduce
        1. Lessons Learned
      5. Wrapping Up
    3. 7. Validation Functions
      1. Document Validation Functions
      2. Validation’s Context
      3. Writing One
        1. Type
        2. Required Fields
        3. Timestamps
        4. Authorship
      4. Wrapping Up
    4. 8. Show Functions
      1. The Show Function API
      2. Side Effect–Free
      3. Design Documents
      4. Querying Show Functions
        1. Design Document Resources
        2. Query Parameters
        3. Accept Headers
      5. Etags
      6. Functions and Templates
        1. The !json Macro
        2. The !code Macro
      7. Learning Shows
      8. Using Templates
      9. Writing Templates
    5. 9. Transforming Views with List Functions
      1. Arguments to the List Function
      2. An Example List Function
      3. List Theory
      4. Querying Lists
      5. Lists, Etags, and Caching
  8. III. Example Application
    1. 10. Standalone Applications
      1. Use the Correct Version
      2. Portable JavaScript
      3. Applications Are Documents
      4. Standalone
      5. In the Wild
      6. Wrapping Up
    2. 11. Managing Design Documents
      1. Working with the Example Application
      2. Installing CouchApp
      3. Using CouchApp
      4. Download the Sofa Source Code
        1. CouchApp Clone
        2. ZIP and TAR Files
        3. Join the Sofa Development Community on GitHub
        4. The Sofa Source Tree
      5. Deploying Sofa
        1. Pushing Sofa to Your CouchDB
        2. Visit the Application
      6. Set Up Your Admin Account
        1. Deploying to a Secure CouchDB
      7. Configuring CouchApp with .couchapprc
    3. 12. Storing Documents
      1. JSON Document Format
      2. Beyond _id and _rev: Your Document Data
      3. The Edit Page
        1. The HTML Scaffold
      4. Saving a Document
        1. Validation
        2. Save Your First Post
      5. Wrapping Up
    4. 13. Showing Documents in Custom Formats
      1. Rendering Documents with Show Functions
        1. The Post Page Template
      2. Dynamic Dates
    5. 14. Viewing Lists of Blog Posts
      1. Map of Recent Blog Posts
      2. Rendering the View as HTML Using a List Function
        1. Sofa’s List Function
        2. The Final Result
  9. IV. Deploying CouchDB
    1. 15. Scaling Basics
      1. Scaling Read Requests
      2. Scaling Write Requests
      3. Scaling Data
      4. Basics First
    2. 16. Replication
      1. The Magic
      2. Simple Replication with the Admin Interface
      3. Replication in Detail
      4. Continuous Replication
      5. That’s It?
    3. 17. Conflict Management
      1. The Split Brain
      2. Conflict Resolution by Example
      3. Working with Conflicts
      4. Deterministic Revision IDs
      5. Wrapping Up
    4. 18. Load Balancing
      1. Having a Backup
    5. 19. Clustering
      1. Introducing CouchDB Lounge
      2. Consistent Hashing
        1. Redundant Storage
        2. Redundant Proxies
        3. View Merging
      3. Growing the Cluster
        1. Moving Partitions
        2. Splitting Partitions
  10. V. Reference
    1. 20. Change Notifications
      1. Polling for Changes
      2. Long Polling
      3. Continuous Changes
      4. Filters
      5. Wrapping Up
    2. 21. View Cookbook for SQL Jockeys
      1. Using Views
        1. Defining a View
        2. Querying a View
        3. MapReduce Functions
          1. Map functions
          2. Reduce functions
      2. Look Up by Key
      3. Look Up by Prefix
      4. Aggregate Functions
      5. Get Unique Values
      6. Enforcing Uniqueness
    3. 22. Security
      1. The Admin Party
        1. Creating New Admin Users
        2. Hashing Passwords
      2. Basic Authentication
        1. Update Validations Again
      3. Cookie Authentication
      4. Network Server Security
    4. 23. High Performance
      1. Good Benchmarks Are Non-Trivial
      2. High Performance CouchDB
        1. Hardware
        2. An Implementation Note
      3. Bulk Inserts and Mostly Monotonic DocIDs
        1. Optimized Examples: Views and Replication
      4. Bulk Document Inserts
      5. Batch Mode
      6. Single Document Inserts
      7. Hovercraft
      8. Trade-Offs
        1. But…My Boss Wants Numbers!
        2. A Call to Arms
    5. 24. Recipes
      1. Banking
        1. Accountants Don’t Use Erasers
        2. Wrapping Up
      2. Ordering Lists
        1. A List of Integers
        2. A List of Floats
      3. Pagination
        1. Example Data
        2. A View
        3. Setup
        4. Slow Paging (Do Not Use)
          1. The dealbreaker
        5. Fast Paging (Do Use)
        6. Jump to Page
  11. VI. Appendixes
    1. A. Installing on Unix-like Systems
      1. Debian GNU/Linux
      2. Ubuntu
      3. Gentoo Linux
      4. Problems
    2. B. Installing on Mac OS X
      1. CouchDBX
      2. Homebrew
      3. MacPorts
    3. C. Installing on Windows
    4. D. Installing from Source
      1. Dependencies
        1. Debian-Based (Including Ubuntu) Systems
        2. Mac OS X
      2. Installing
      3. Security Considerations
      4. Running Manually
      5. Running As a Daemon
        1. SysV/BSD-Style Systems
        2. Mac OS X
      6. Troubleshooting
    5. E. JSON Primer
      1. Data Types
        1. Numbers
        2. Strings
        3. Booleans
        4. Arrays
        5. Objects
        6. Nulls
    6. F. The Power of B-trees
  12. Index
  13. About the Authors
  14. Colophon
  15. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  16. Copyright

Product information

  • Title: CouchDB: The Definitive Guide
  • Author(s): J. Chris Anderson, Jan Lehnardt, Noah Slater
  • Release date: January 2010
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449382933