Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
The Official MongoDB Guide
The Official MongoDB Guide

The Official MongoDB Guide: Resilience, scalability, security and performance

Arrow left icon
Profile Icon Rachelle Palmer Profile Icon Jeffrey Allen Profile Icon Parker Faucher Profile Icon Alison Huh Profile Icon Lander Kerbey Profile Icon Maya Raman Profile Icon Lauren Tran +3 more Show less
Arrow right icon
$53.98 $59.99
eBook Sep 2025 368 pages 1st Edition
eBook
$53.98 $59.99
Paperback
$74.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Rachelle Palmer Profile Icon Jeffrey Allen Profile Icon Parker Faucher Profile Icon Alison Huh Profile Icon Lander Kerbey Profile Icon Maya Raman Profile Icon Lauren Tran +3 more Show less
Arrow right icon
$53.98 $59.99
eBook Sep 2025 368 pages 1st Edition
eBook
$53.98 $59.99
Paperback
$74.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$53.98 $59.99
Paperback
$74.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

The Official MongoDB Guide

MongoDB Architecture

MongoDB is designed to support the evolving needs of modern applications through a developer-centric data platform based on a set of core architectural principles. In this chapter, we’ll explore the architectural framework that powers MongoDB, with a particular focus on two foundational concepts: replication and sharding.

Replication plays a vital role in MongoDB’s distributed design by enhancing both availability and fault tolerance. By maintaining several copies of your data across multiple servers, MongoDB ensures that your application can continue functioning even if one server fails.

Sharding is a horizontal scaling strategy for spreading data across several machines, called shards. Each shard stores a portion of the total dataset on a separate database server instance. As applications grow in popularity, and the volume of data they produce increases, scaling across machines becomes essential to ensure sufficient read and write throughput...

Replication

A replica set in MongoDB is a group of mongod processes that maintain the same set of data. It provides redundancy and high availability and is the basis for all production deployments. By having several copies of your data across database servers, replication ensures a degree of fault tolerance, protecting against the loss of a single database server.

Maintaining copies of data in different data centers can increase data locality and availability for distributed applications. In some cases, replication can provide increased read capacity as clients are able to send read operations to different servers.

A replica set includes one primary node, which handles all write operations and logs all dataset changes in its operations log (oplog). The secondary nodes replicate the primary’s oplog and implement the operations on their own datasets. This ensures that they mirror the primary’s dataset. In the event that the primary becomes inaccessible, a qualified...

Compaction

You can leverage compaction to release unneeded disk space, taken up by data and collection indexes, to the operating system. To do this, run the compact command on one of your deployment’s secondary nodes. The command has the following syntax:

db.runCommand({
   compact: <string>,
   dryRun: <boolean>,
   force: <boolean>,
   freeSpaceTargetMB: <int>,
   comment: <any>
}) 

You can specify the following compact options:

  • compact: The name of the collection you want to run compaction on.
  • dryRun: If set to true, returns an estimate of how much space, in bytes, compaction can reclaim from the targeted collection. If dryRun is enabled, the compact command doesn’t perform any kind of compaction and only returns the estimated value.
  • force: (Optional) If enabled, forces compact to run on the primary member of your replica set.
  • freeSpaceTargetMB: (Optional) Specifies the minimum amount of...

TCMalloc performance optimization

Starting in MongoDB 8.0, MongoDB uses an upgraded version of TCMalloc that uses per-CPU caches, which locally store memory for a specific CPU core and drastically reduce memory fragmentation when compared to the previously used per-thread caches. As a result, the new TCMalloc helps reduce memory fragmentation and makes your database more resilient to high-stress workloads. This reduced fragmentation can improve the read performance of your replica set, especially secondaries that serve read queries.

Platform support

All operating systems that support MongoDB 8.0 also support the updated TCMalloc, except for the following:

  • RHEL 8/Oracle 8 on the PPC64LE and s390x architectures
  • RHEL 9/CentOS 9 / Oracle 9 on the PPC64LE architecture
  • All Windows operating systems

Enabling Transparent Huge Pages (THP)

If you’re running a self-managed MongoDB deployment on a Linux system, ensure that you enable Transparent...

Replication versus sharding

Replication and sharding are often confused with each other, but they serve fundamentally different roles. Replication involves creating multiple copies of the same data across different servers. Its primary goal is to provide fault tolerance, high availability, and redundancy, ensuring your application remains operational even if a node goes down. On the other hand, sharding is a horizontal scaling method that breaks a large dataset into smaller, more manageable pieces, called shards, and distributes those shards across multiple server instances. Each shard holds only a subset of the overall data, which improves performance and allows the system to handle more data than a single server could manage.

However, replication and sharding work together in that each shard must implement replication to maintain data integrity and availability. Each shard in a sharded cluster should be configured as a replica set to protect against data loss and system outages...

Sharding

MongoDB supports horizontal scaling through sharding, which involves the distribution of data across multiple servers, divided into smaller pieces known as shards. Sharding plays an essential role in managing and organizing large-scale data.

Moreover, sharding allows for the creation of distributed databases to support geographically distributed applications, enabling policies that enforce data residency within specific regions.

Why do you need sharding?

Imagine your application’s data is growing rapidly and starting to push the limits of your database. As data volume increases, you may encounter a range of issues, the most immediate being degraded performance. Queries that once returned results quickly may now take noticeably longer, slowing down your application and frustrating users with laggy or delayed responses.

Storage is another critical concern. Every system has practical limits on how much data it can store and manage efficiently. If your...

Summary

In this chapter, we covered the foundational elements of MongoDB’s architecture, defining replication and sharding, detailing key features that you can use in production, and introducing some new features in MongoDB 8.0 that can help maximize your deployment’s performance.

Regarding replication, we learned about the critical role that it plays in ensuring data availability and fault tolerance within MongoDB, including the replica set election process, the importance of the oplog, and how you can configure your replica set to enhance read scalability. Furthermore, we introduced new features, such as background compaction and the updated TCMalloc, that help manage memory usage and, in turn, increase the efficiency of your deployment.

With sharding, this chapter provided a comprehensive overview of sharding as a strategy for horizontal scaling. We learned how sharding distributes data across multiple servers to manage large datasets and high-traffic applications...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Design resilient, secure solutions with high performance and scalability
  • Streamline development with modern tooling, indexing, and AI-powered workflows
  • Deploy and optimize in the cloud using advanced MongoDB Atlas features
  • Purchase of the print or Kindle book includes a free PDF eBook

Description

Delivering secure, scalable, and high-performance applications is never easy, especially when systems must handle growth, protect sensitive data, and perform reliably under pressure. The Official MongoDB Guide addresses these challenges with guidance from MongoDB’s top subject matter experts, so you learn proven best practices directly from those who know the technology inside out. This book takes you from core concepts and architecture through to advanced techniques for data modeling, indexing, and query optimization, supported by real-world patterns that improve performance and resilience. It offers practical coverage of developer tooling, IDE integrations, and AI-assisted workflows that will help you work faster and more effectively. Security-focused chapters walk you through authentication, authorization, encryption, and compliance, while chapters dedicated to MongoDB Atlas showcase its robust security features and demonstrate how to deploy, scale, and leverage platform-native capabilities such as Atlas Search and Atlas Vector Search. By the end of this book, you’ll be able to design, build, and manage MongoDB applications with the confidence that comes from learning directly from the experts shaping the technology.

Who is this book for?

This book is for developers, database professionals, architects, and platform teams who want to get the most out of MongoDB. Whether you’re building web apps, APIs, mobile services, or backend systems, the concepts covered here will help you structure data, improve performance, and deliver value to your users. No prior experience with MongoDB is required, but familiarity with databases and programming will be helpful.

What you will learn

  • Build secure, scalable, and high-performance applications
  • Design efficient data models and indexes for real workloads
  • Write powerful queries to sort, filter, and project data
  • Protect applications with authentication and encryption
  • Accelerate coding with AI-powered and IDE-based tools
  • Launch, scale, and manage MongoDB Atlas with confidence
  • Unlock advanced features like Atlas Search and Atlas Vector Search
  • Apply proven techniques from MongoDB's own engineering leaders

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 05, 2025
Length: 368 pages
Edition : 1st
Language : English
ISBN-13 : 9781837021963
Vendor :
MongoDB
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Sep 05, 2025
Length: 368 pages
Edition : 1st
Language : English
ISBN-13 : 9781837021963
Vendor :
MongoDB
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Table of Contents

11 Chapters
Introduction to MongoDB Chevron down icon Chevron up icon
MongoDB Architecture Chevron down icon Chevron up icon
Developer Tools Chevron down icon Chevron up icon
Data Modeling and Index Optimization Chevron down icon Chevron up icon
Queries Chevron down icon Chevron up icon
Database Operations Chevron down icon Chevron up icon
Security Chevron down icon Chevron up icon
MongoDB Atlas Chevron down icon Chevron up icon
Atlas Search Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon