MongoDB : The Definitive Guide

Embed Size (px)

Citation preview

MongoDBThe Definitive Guide

Wildan [email protected]

1. Introduction

A Rich Data Model

Easy Scaling

Tons of Features

Without Sacrificing Speed

Simple Administration

But Wait, Thats Not All

2. Getting Started

Documents

CollectionsSchema-Free

Naming

Databases

Getting and Starting MongoDB

MongoDB ShellRunning the Shell

A MongoDB Client

Basic Operations with the Shell

Tips for Using the Shell

Data TypesBasic Data Types

Numbers

Dates

Arrays

Embedded Documents

_id and ObjectIds

3. Creating, Updating, and Deleting Documents

Inserting and Saving DocumentsBatch Insert

Inserts: Internals and Implications

Removing DocumentsRemove Speed

Updating DocumentsDocument Replacement

Using Modifiers

Upserts

Updating Multiple Documents

Returning Updated Documents

The Fastest Write This Side of MississippiSafe Operation

Catching Normal Errors

Requests and Connections

4. Querying

Introduction to findSpecifying Which Keys to Return

Limitations

Query CriteriaQuery Conditionals

OR Queries

$not

Rules for Conditionals

Type-Specific QueriesNull

Regular Expressions

Querying Arrays

Querying on Embedded Documents

$where Queries

CursorsLimits, Skips, and Sorts

Avoiding Large Skips

Advanced Query Options

Getting Consistent Results

Cursor Internals

5. Indexing

Introduction to IndexingScaling Indexes

Indexing Keys in Embedded Documents

Indexing for Sorts

Uniquely Identifying Indexes

Unique IndexesDropping Duplicates

Compound Unique Indexes

Using explain and hint

Index AdministrationChanging Indexes

Geospatial IndexingCompound Geospatial Indexes

The Earth Is Not a 2D Plane

6. Aggregation

Count

Distinct

GroupUsing a Finalizer

Using a Function as a Key

MapReduceExample 1: Finding All Keys in a Collection

Example 2: Categorizing Web Pages

MongoDB and MapReduce

7. Advanced Topics

Database CommandsHow Commands Work

Command Reference

Capped CollectionsProperties and Use Cases

Creating Capped Collections

Sorting Au NaturelTailable Cursors

GridFS: Storing FilesGetting Started with GridFS: mongofiles

Working with GridFS from the MongoDB Drivers

Under the Hood

Server-Side Scriptingdb.eval

Stored JavaScript

Security

Database ReferencesWhat Is a DBRef?

Example Schema

Driver Support for DBRefs

When Should DBRefs Be Used?

8. Administration

Starting and Stopping MongoDBStarting from the Command Line

File-Based Configuration

Stopping MongoDB

MonitoringUsing the Admin Interface

serverStatus

Mongostat

Third-Party Plug-Ins

Security and AuthenticationAuthentication Basics

How Authentication Works

Other Security Considerations

Backup and RepairData File Backup

mongodump and mongorestore

fsync and Lock

Slave Backups

Repair

9. Replication

Master-Slave ReplicationOptions

Adding and Removing Sources

Replica SetsInitializing a Set

Nodes in a Replica Set

Failover and Primary Election

Performing Operations on a SlaveRead Scaling

Using Slaves for Data Processing

How It WorksThe Oplog

Syncing

Replication State and the Local Database

Blocking for Replication

AdministrationDiagnostics

Changing the Oplog Size

Replication with Authentication

10. Sharding

Introduction to ShardingAutosharding in MongoDB

When to Shard

The Key to Sharding: Shard KeysSharding an Existing Collection

Incrementing Shard Keys Versus Random Shard Keys

How Shard Keys Affect Operations

Setting Up ShardingStarting the Servers

Sharding Data

Production ConfigurationA Robust Config

Many mongos

A Sturdy Shard

Physical Servers

Sharding Administrationconfig Collections

Sharding Commands

11. Example Applications

Chemical Search Engine: JavaInstalling the Java Driver

Using the Java Driver

Schema Design

Writing This in Java

Issues

News Aggregator: PHPInstalling the PHP Driver

Using the PHP Driver

Designing the News Aggregator

Trees of Comments

Voting

Custom Submission Forms: RubyInstalling the Ruby Driver

Using the Ruby Driver

Custom Form Submission

Ruby Object Mappers and Using MongoDB with Rails

Real-Time Analytics: PythonInstalling PyMongo

Using PyMongo

MongoDB for Real-Time Analytics

Schema

Handling a Request

Using Analytics Data

Other Considerations

A. Installing MongoDB

B. mongo: The Shell

C. MongoDB Internals

Buy this book, on Amazon!

Q&A

Thanks! ^_^

2010, OpenThink Labs. All Rights Reserved