O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

MongoDB Administrator’s Guide

Book Description

Manage, fine-tune, secure and deploy your MongoDB solution with ease with the help of practical recipes

About This Book

  • Configure and deploy your MongoDB instance securely, without any hassle
  • Optimize your database's query performance, perform scale-out operations, and make your database highly available
  • Practical guide with a recipe-based approach to help you tackle any problem in the application and database administration aspects of MongoDB

Who This Book Is For

Database administrators with a basic understanding of the features of MongoDB and who want to professionally configure, deploy, and administer a MongoDB database, will find this book essential. If you are a MongoDB developer and want to get into MongoDB administration, this book will also help you.

What You Will Learn

  • Install and deploy MongoDB in production
  • Manage and implement optimal indexes
  • Optimize monitoring in MongoDB
  • Fine-tune the performance of your queries
  • Debug and diagnose your database's performance
  • Optimize database backups and recovery and ensure high availability
  • Make your MongoDB instance scalable
  • Implement security and user authentication features in MongoDB
  • Master optimal cloud deployment strategies

In Detail

MongoDB is a high-performance and feature-rich NoSQL database that forms the backbone of the systems that power many different organizations. Packed with many features that have become essential for many different types of software professional and incredibly easy to use, this cookbook contains more than 100 recipes to address the everyday challenges of working with MongoDB.

Starting with database configuration, you will understand the indexing aspects of MongoDB. The book also includes practical recipes on how you can optimize your database query performance, perform diagnostics, and query debugging. You will also learn how to implement the core administration tasks required for high-availability and scalability, achieved through replica sets and sharding, respectively. You will also implement server security concepts such as authentication, user management, role-based access models, and TLS configuration. You will also learn how to back up and recover your database efficiently and monitor server performance.

By the end of this book, you will have all the information you need—along with tips, tricks, and best practices—to implement a high-performance MongoDB solution.

Style and approach

This practical book follows a problem-solution approach to help you tackle any issues encountered while performing MongoDB administrative tasks. Each recipe is detailed, and explained in a very easy to understand manner

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Installation and Configuration
    1. Introduction
    2. Installing and starting MongoDB on Linux
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
    3. Installing and starting MongoDB on macOS
      1. Getting ready
      2. How to do it...
      3. How it works…
    4. Binding MongoDB process to a specific network interface and port
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Enabling SSL for MongodDB
      1. Getting ready
      2. How to do it..
      3. How it works...
      4. There's more…
    6. Choosing the right MongoDB storage engine
      1. WiredTiger
      2. MMAPv1
      3. The verdict
    7. Changing storage engine
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Separating directories per database
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Customizing the MongoDB configuration file
      1. Getting ready
      2. How to do it..
      3. How it works...
      4. There's more...
    10. Running MongoDB as a Docker container
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more..
  3. Understanding and Managing Indexes
    1. Introduction
    2. Creating an index
      1. Getting ready
      2. How it works...
      3. There's more...
    3. Managing existing indexes
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. How to use compound indexes
      1. Getting ready
      2. How to do it...
      3. How it works…
      4. There's more...
    5. Creating background indexes
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating TTL-based indexes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Creating a sparse index
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a partial index
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Creating a unique index
      1. Getting ready
      2. How to do it...
      3. How it works...
  4. Performance Tuning
    1. Introduction
    2. Configuring disks for better I/O
      1. Reading and writing from disks
      2. Few considerations while selecting storage devices
    3. Measuring disk I/O performance with mongoperf
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Finding slow running queries and operations
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Storage considerations when using Amazon EC2
    6. Figuring out the size of a working set
      1. There's more...
  5. High Availability with Replication
    1. Introduction
    2. Initializing a new replica set
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Adding a node to the replica set
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Removing a node from the replica set
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Working with an arbiter
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Switching between primary and secondary nodes
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Changing replica set configuration
      1. Getting ready
      2. How to do it...
      3. How it works..
    8. Changing priority to replica set nodes
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  6. High Scalability with Sharding
    1. Understanding sharding and its components
      1. Components of MongoDB sharding infrastructure
        1. Config server
        2. The mongos query router
        3. The shard server
      2. Choosing the shard key
    2. Setting up and configuring a sharded cluster
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Managing chunks
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Moving non-sharded collection data from one shard to another
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Removing a shard from the cluster
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Understanding tag aware sharding – zones
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  7. Managing MongoDB Backups
    1. Introduction
    2. Taking backup using mongodump tool
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Taking backup of a specific mongodb database or collection
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Taking backup of a small subset of documents in a collection
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Using bsondump tool to view mongodump output in human readable form
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Creating a point in time backup of replica sets
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using the mongoexport tool
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Creating a backup of a sharded cluster
      1. Getting ready
      2. How to do it...
      3. How it works...
  8. Restoring MongoDB from Backups
    1. Introduction
    2. Restoring standalone MongoDB using the mongorestore tool
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Restoring specific database or specific collection
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Restoring data from one collection or database to another
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Creating a new MongoDB replica set node using backups
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Restoring a MongoDB sharded cluster from backup
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Monitoring MongoDB
    1. Introduction
    2. Monitoring MongoDB performance with mongostat
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    3. Checking replication lag of nodes in a replica set
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Monitoring and killing long running operations on MongoDB
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
    5. Checking disk I/O usage
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Collecting MongoDB metrics using Diamond and Graphite
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also
  10. Authentication and Security in MongoDB
    1. Introduction
    2. Setting up authentication in MongoDB and creating a superuser account
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Creating normal users and assigning built-in roles
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also...
    4. Creating and assigning custom roles
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Restoring access if you are locked out
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using key files to authenticate servers in a replica set
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  11. Deploying MongoDB in Production
    1. Introduction
    2. Configuring MongoDB for a production deployment
      1. Getting ready
      2. How to do it...
    3. Upgrading production MongoDB to a newer version
      1. Getting ready
      2. How to do it...
      3. There's more...
    4. Setting up and configuring TLS (SSL)
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    5. Restricting network access using firewalls
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. See also