MongoDB in Action, Second Edition
Covers MongoDB version 3.0
Kyle Banker, Peter Bakkum, Shaun Verch, Douglas Garrett, and Tim Hawkins
  • March 2016
  • ISBN 9781617291609
  • 480 pages
  • printed in black & white
free previous edition eBook included
An eBook copy of the previous edition of this book is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

A thorough manual for learning, practicing, and implementing MongoDB

Jeet Marwah, Acer Inc.


An eBook copy of the previous edition, MongoDB in Action (First Edition), is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

MongoDB in Action, Second Edition is a completely revised and updated version. It introduces MongoDB 3.0 and the document-oriented database model. This perfectly paced book gives you both the big picture you'll need as a developer and enough low-level detail to satisfy system engineers.

About the Technology

This document-oriented database was built for high availability, supports rich, dynamic schemas, and lets you easily distribute data across multiple servers. MongoDB 3.0 is flexible, scalable, and very fast, even with big data loads.

About the book

MongoDB in Action, Second Edition is a completely revised and updated version. It introduces MongoDB 3.0 and the document-oriented database model. This perfectly paced book gives you both the big picture you'll need as a developer and enough low-level detail to satisfy system engineers. Lots of examples will help you develop confidence in the crucial area of data modeling. You'll also love the deep explanations of each feature, including replication, auto-sharding, and deployment.

Table of Contents detailed table of contents

Part 1 Getting Started

1. A database for the modern web

1.1. Built for the internet

1.2. MongoDB's key features

1.2.1. Document data model

1.2.2. Ad hoc queries

1.2.3. Indexes

1.2.4. Replication

1.2.5. Speed and durability

1.2.6. Scaling

1.3. MongoDB's core server and tools

1.3.1. Core server

1.3.2. JavaScript shell

1.3.3. Database drivers

1.3.4. Command-line tools

1.4. Why MongoDB?

1.4.1. MongoDB versus other databases

1.4.2. Use cases and production deployments

1.5. Tips and limitations

1.6. History of MongoDB

1.7. Additional resources

1.8. Summary

2. MongoDB through the JavaScript shell

2.1. Diving into the MongoDB shell

2.1.1. Starting the shell

2.1.2. Databases, collections, and documents

2.1.3. Inserts and queries

2.1.4. Updating documents

2.1.5. Deleting data

2.1.6. Other shell features

2.2. Creating and querying with indexes

2.2.1. Creating a large collection

2.2.2. Indexing and explain( )

2.3. Basic administration

2.3.1. Getting database information

2.3.2. How commands work

2.4. Getting help

2.5. Summary

3. Writing programs using MongoDB

3.1. MongoDB through the Ruby lens

3.1.1. Installing and connecting

3.1.2. Inserting documents in Ruby

3.1.3. Queries and cursors

3.1.4. Updates and deletes

3.1.5. Database commands

3.2. How the drivers work

3.2.1. Object ID generation

3.3. Building a simple application

3.3.1. Setting up

3.3.2. Gathering data

3.3.3. Viewing the archive

3.4. Summary

Part 2: Application development in MongoDB

4. Document-oriented data

4.1. Principles of schema design

4.2. Designing an e-commerce data model

4.2.1. Schema basics

4.2.2. Users and orders

4.2.3. Reviews

4.3. Nuts and bolts: On databases, collections, and documents

4.3.1. Databases

4.3.2. Collections

4.3.3. Documents and insertion

4.4. Summary

5. Constructing queries

5.1. E-commerce queries

5.1.1. Products, categories, and reviews

5.1.2. Users and orders

5.2. MongoDB's query language

5.2.1. Query Criteria and Selectors

5.2.2. Query options

5.3. Summary

6. Aggregation

6.1. Aggregation framework overview

6.2. E-commerce aggregation example

6.2.1. Products, categories, and reviews

6.2.2. User and order

6.3. Aggregation pipeline operators

6.3.1. $project

6.3.2. $group

6.3.3. $match, $sort, $skip, $limit

6.3.4. $unwind

6.3.5. $out

6.4. Reshaping documents

6.4.1. String functions

6.4.2. Arithmetic functions

6.4.3. Date functions

6.4.4. Logical functions

6.4.5. Set Operators

6.4.6. Miscellaneous functions

6.5. Understanding aggregation pipeline performance

6.5.1. Aggregation pipeline options

6.5.2. The aggregation framework's explain( ) function

6.5.3. allowDiskUse option

6.5.4. Aggregation cursor option

6.6. Other aggregation capabilities

6.6.1. .count( ) and .distinct( )

6.6.2. map-reduce

6.7. Summary

7. Updates, atomic operations, and deletes

7.1. A brief tour of document updates

7.1.1. Modify by replacement

7.1.2. Modify by operator

7.1.3. Both methods compared

7.1.4. Deciding: Replacement vs. operators

7.2. E-commerce updates

7.2.1. Products and categories

7.2.2. Reviews

7.2.3. Orders

7.3. Atomic document processing

7.3.1. Order state transitions

7.3.2. Inventory management

7.4. Nuts and bolts: MongoDB updates and deletes

7.4.1. Update types and options

7.4.2. Update operators

7.4.3. The findAndModify command

7.4.4. Deletes

7.4.5. Concurrency, atomicity, and isolation

7.4.6. Update performance notes

7.5. Reviewing update operators

7.6. Summary

Part 3: MongoDB mastery

8. Indexing and query optimization

8.1. Indexing theory

8.1.1. A thought experiment

8.1.2. Core indexing concepts

8.1.3. B-trees

8.2. Indexing in practice

8.2.1. Index types

8.2.2. Index administration

8.3. Query optimization

8.3.1. Identifying slow queries

8.3.2. Examining slow queries

8.3.3. Query patterns

8.4. Summary

9. Text search

9.1. Text searches—not just pattern matching

9.1.1. Text searches vs. pattern matching

9.1.2. Text searches vs. web page searches

9.1.3. MongoDB text search vs. dedicated text search engines

9.2. Manning book catalog data download

9.3. Defining text search indexes

9.3.1. Text index size

9.3.2. Assigning an index name and indexing all text fields in a collection

9.4.1. More complex searches

9.4.2. Text search scores

9.4.3. Sorting results by text search score

9.5.1. Where's MongoDB in Action, Second Edition?

9.6. Text search languages

9.6.1. Specifying language in the index

9.6.2. Specifying the language in the document

9.6.4. Available languages

9.7. Summary

10. WiredTiger and pluggable storage

10.1. Pluggable Storage Engine API

10.1.1. Why use different storages engines?

10.2. WiredTiger

10.2.1. Switching to WiredTiger

10.2.2. Migrating your database to WiredTiger

10.3. Comparison with MMAPv1

10.3.1. Configuration files

10.3.2. Insertion script and benchmark script

10.3.3. Insertion benchmark results

10.3.4. Read performance scripts

10.3.5. Read performance results

10.3.6. Benchmark conclusion

10.4. Other examples of pluggable storage engines

10.5. Advanced topics

10.5.1. How does a pluggable storage engine work?

10.5.2. Data structure

10.5.3. Locking

10.6. Summary

11. Replication

11.1. Replication overview

11.1.1. Why replication matters

11.1.2. Replication use cases and limitations

11.2. Replica sets

11.2.1. Setup

11.2.2. How replication works

11.2.3. Administration

11.3. Drivers and replication

11.3.1. Connections and failover

11.3.2. Write concern

11.3.3. Read scaling

11.3.4. Tagging

11.4. Summary

12. Scaling your system with Sharding

12.1. Sharding overview

12.1.1. What is sharding?

12.1.2. When should you shard?

12.2. Understanding components of a sharded cluster

12.2.1. Shards: Storage of application data

12.2.2. Mongos router: Router of operations

12.2.3. Config servers: Storage of metadata

12.3. Distributing data in a sharded cluster

12.3.1. Ways data can be distributed in a sharded cluster

12.3.2. Distributing databases to shards

12.3.3. Sharding within collections

12.4. Building a sample shard cluster

12.4.1. Starting the mongod and mongos servers

12.4.2. Configuring the cluster

12.4.3. Sharding collections

12.4.4. Writing to a sharded cluster

12.5. Querying and indexing a shard cluster

12.5.1. Query routing

12.5.2. Indexing in a sharded cluster

12.5.3. The explain() tool in a sharded cluster

12.5.4. Aggregation in a sharded cluster

12.6. Choosing a shard key

12.6.1. Imbalanced writes (hotspots)

12.6.2. Unsplittable chunks (coarse granularity)

12.6.3. Poor targeting (shard key not present in queries)

12.6.4. Ideal shard keys

12.6.5. Inherent design trade-offs (email application)

12.7. Sharding in production

12.7.1. Provisioning

12.7.2. Deployment

12.7.3. Maintenance

12.8. Summary

13. Deployment and administration

13.1. Hardware and provisioning

13.1.1. Cluster topology

13.1.2. Deployment environment

13.1.3. Provisioning

13.2. Monitoring and diagnostics

13.2.1. Logging

13.2.2. MongoDB diagnostic commands

13.2.3. MongoDB diagnostic tools

13.2.4. MongoDB Monitoring Service

13.2.5. External monitoring applications

13.3. Backups

13.3.1. mongodump and mongorestore

13.3.2. Data file—based backups

13.3.3. MMS backups

13.4. Security

13.4.1. Secure environments

13.4.2. Network encryption

13.4.3. Authentication

13.4.4. Replica set authentication

13.4.5. Sharding authentication

13.4.6. Enterprise security features

13.5. Administrative tasks

13.5.1. Data imports and exports

13.5.2. Compaction and repair

13.5.3. Upgrading

13.6. Performance troubleshooting

13.6.1. Working set

13.6.2. Performance cliff

13.6.3. Query interactions

13.6.4. Seek professional assistance

13.7. Deployment checklist

13.8. Summary


Appendix A: Installation

A.1. Installation

A.1.1. Production deployments

A.1.2. 32-bit vs. 64-bit

A.2. MongoDB on Linux

A.2.1. Installing with precompiled binaries

A.2.2. Using a package manager

A.3. MongoDB on Mac OS X

A.3.1. Precompiled binaries

A.3.2. Using a package manager

A.4. MongoDB on Windows

A.4.1. Precompiled binaries

A.5. Compiling MongoDB from source

A.6. Troubleshooting

A.6.1. Wrong architecture

A.6.2. Nonexistent data directory

A.6.3. Lack of permissions

A.6.4. Unable to bind to port

A.7. Basic configuration options

A.8. Installing Ruby

A.8.1. Linux and Mac OS X

A.8.2. Windows

Appendix B: Design patterns

B.1. Embed vs. reference

B.2. One-to-many

B.3. Many-to-many

B.4. Trees

B.5. Worker queues

B.6. Dynamic attributes

B.7. Transactions

B.8. Locality and precomputation

B.9. Antipatterns

B.9.1. Careless indexing

B.9.2. Motley types

B.9.3. Bucket collections

B.9.4. Large, deeply nested documents

B.9.5. One collection per user

B.9.6. Unshardable collections

Appendix C: Binary data and GridFS

C.1. Simple binary storage

C.1.1. Storing a thumbnail

C.1.2. Storing an MD5

C.2. GridFS

C.2.1. GridFS in Ruby

C.2.2. GridFS with mongofiles

What's inside

  • Indexes, queries, and standard DB operations
  • Aggregation and text searching
  • Map-reduce for custom aggregations and reporting
  • Deploying for scale and high availability
  • Updated for Mongo 3.0

About the reader

Written for developers. No previous MongoDB or NoSQL experience is assumed.

About the authors

After working at MongoDB, Kyle Banker is now at a startup. Peter Bakkum is a developer with MongoDB expertise. Shaun Verch has worked on the core server team at MongoDB. A Genentech engineer, Doug Garrett is one of the winners of the MongoDB Innovation Award for Analytics. A software architect, Tim Hawkins has led search engineering at Yahoo Europe.

Technical Contributor: Wouter Thielen

Technical Editor: Mihalis Tsoukalos

placing your order...

Don't refresh or navigate away from the page.
print book $33.74 $44.99 pBook + eBook + liveBook
includes previous edition eBook
Additional shipping charges may apply
Prints and ships within 3-5 days
MongoDB in Action, Second Edition (print book) added to cart
continue shopping
go to cart

eBook $26.99 $35.99 3 formats + liveBook
includes previous edition eBook
MongoDB in Action, Second Edition (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks