The Official MongoDB Guide - Rachelle Palmer - E-Book

The Official MongoDB Guide E-Book

Rachelle Palmer

0,0
53,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 457

Veröffentlichungsjahr: 2025

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



The Official MongoDB Guide

Resilience, scalability, security and performance

Rachelle Palmer

Jeffrey Allen

Parker Faucher

Alison Huh

Lander Kerbey

Maya Raman

Lauren Tran

The Official MongoDB Guide

Copyright © 2025 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damage caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Portfolio Director: Sunith Shetty

Relationship Lead: Sathya Mohan

Project Managers: Sathya Mohan & Aniket Shetty

Content Engineer: Saba Umme Salma

Technical Editor: Aniket Shetty

Copy Editor: Safis Editing

Indexer: Rekha Nair

Production Designer: Deepak Chavan

First published: September 2025

Production reference: 1220825

Published by Packt Publishing Ltd.

Grosvenor House

11 St Paul’s Square

Birmingham

B3 1RB, UK.

ISBN 978-1-83702-197-0

www.packtpub.com

Contributors

About the authors

Rachelle Palmer is the Product Leader for Developer Database Experience and Developer Education at MongoDB, overseeing the driver client libraries, documentation, framework integrations, and MongoDB University. She has built sample applications for MongoDB in Java, PHP, Rust, Python, Node.js, and Ruby. Rachelle joined MongoDB in 2013 and was previously the director of the technical services engineering team, creating and managing the team that provided support and CloudOps to MongoDB Atlas.

Jeffery Allen is a Technical Writer at MongoDB, based in the New York City area. He focuses on server documentation and works closely with Product and Engineering teams to develop examples that reflect real-world use cases, especially pertaining to data modeling and the MongoDB query language. Before joining MongoDB, Jeff worked as a full-stack web developer. Jeff also enjoys playing guitar and piano, and produces electronic music in his spare time.

Parker Faucher is a self-taught Software Engineer with over six years of experience in technical education. He has authored more than 100 educational videos for MongoDB, establishing himself as a knowledgeable resource in database technologies. Currently, Parker focuses on Artificial Intelligence and Search technologies, exploring innovative solutions in these rapidly evolving fields. When not advancing his technical expertise, Parker enjoys spending quality time with his family and maintains an avid interest in collecting comic books.

Alison Huh is a New York City-based Technical Writer on MongoDB’s server documentation team. In addition to the core database, she focuses on documenting MongoDB user tools such as Compass, Mongosync, and IDE extensions. Outside of MongoDB, Alison is currently pursuing her M.A. in Instructional Technology and Media at Teachers College, Columbia University, exploring the intersections of design, digital media, and learning. In her free time, Alison loves going on runs, crafting small trinkets, and experiencing live music.

Lander Kerbey is a Technical Writer at MongoDB, specializing in Atlas Stream Processing. Prior to MongoDB, he worked at InterSystems, documenting various parts of the HealthShare suite, along with their various data analytics tools. His 11 years of experience as an educator informs his approach to documentation, as he strives to create “Aha!” moments for users.

Maya Raman is a Technical Writer and sometimes-software engineer at MongoDB. She is passionate about the intersections between the environment, art and literature, technology, and people. She is based in New York City and likes to spend her time hanging out in Prospect Park, even in winter.

Lauren Tran is a Technical Writer at MongoDB with a background in Communications and Computer Science. She is on the Server Documentation team and mainly specializes in Information Architecture, Time Series data, and Search. Lauren is passionate about creating accessible and inclusive documentation that caters to diverse audiences. She is based in Chicago following four years in New York City and in her free time, enjoys reading on the beach at Lake Michigan and listening to Taylor Swift music.

About the reviewers

Sarah Evans is a Curriculum Engineer at MongoDB, where she specializes in making complex technical concepts accessible for all learners. With over ten years of experience in software engineering, education, and developing curriculum for technical bootcamps, she’s all about making learning MongoDB less intimidating and more exciting. When she’s not helping developers level up their database skills, Sarah can be found having spontaneous dance parties with her family, exploring the great outdoors with her dog, or tending to her garden.

Manuel Fontan is a Senior Technologist on the Curriculum team at MongoDB. Previously he was a Senior Technical Services Engineer in the Core team at MongoDB. In between Manuel worked as a database reliability engineer at Slack for a little over 2 years and then for Cognite until he re-joined MongoDB. With over 15 years of experience in software development and distributed systems, he is naturally curious and holds a Telecommunications Engineering MSc from Vigo University (Spain) and a Free and Open Source Software MSc from Rey Juan Carlos University (Spain).

Contents

Preface

How this book will help you

Who this book is for

What this book covers

To get the most out of this book

Get in touch

Introduction to MongoDB

Why MongoDB?

Who uses MongoDB?

MongoDB architecture

Clusters

Sharded clusters

Collections

What’s new in MongoDB?

Performance

Encryption

Cost and scaling

Resilience

Summary

MongoDB Architecture

Replication

Replica set elections

Replication election protocol

Heartbeats

Member priority

Mirrored reads

Loss of a data center

Network partition

Replica set oplog

Oplog buffers

The oplog window

Oplog size

Replica set deployment architecture

Strategies for deploying replica sets

Replica set arbiter

Hidden replica set members

Fault tolerance

Adding capacity ahead of demand

Geographic distribution

Read-heavy applications

Example deployment architectures

Primary with two secondary members

Primary with a secondary member and an arbiter

Three-member replica set distributed across two data centers

Five-member replica set distributed across three data centers

Write concern

Read preference

Read concern

Compaction

Background compaction

TCMalloc performance optimization

Platform support

Enabling Transparent Huge Pages (THP)

Enabling per-CPU caches

Replication methods

Replication commands

Replication versus sharding

Sharding

Why do you need sharding?

Key elements of a sharded cluster

Config shards

Converting a replica set to a sharded cluster with a config shard

Transitioning from a config shard to a dedicated config server

Advantages of sharding

Data distribution

Shard key

Resharding a collection

Refining a shard key

Chunks

Ranges

Zones

Balancer

Balancing window

Sharding strategies

Ranged sharding

Hashed sharding

Hashed versus ranged sharding scenarios

Production configurations

Development configuration

Sharded and non-sharded collections

Unsharding a collection

Moving an unsharded collection

Querying sharded data

Find operations

sort(), limit(), and skip() operations

Update and delete operations

Hedged reads

Sharding methods

Summary

Developer Tools

Integrated development environment extensions

MongoDB for VS Code extension

Getting started with the VS Code extension

Data exploration

Query prototyping

CRUD capabilities in the MongoDB Playground for VS Code

Prototyping aggregations in the MongoDB Playground for VS Code

MongoDB IDE extension for IntelliJ

Compass

Getting started

Interacting with your data

Managing documents

Querying documents in MongoDB Compass

Natural language querying in Compass

MongoDB MCP Server

Summary

Data Modeling and Index Optimization

Document data model

BSON and its data types

Embedded data

Schema design

Identify the application workload

Map schema relationships

Optimizing queries for articles

Optimizing queries for articles and authors

Modeling relationships

One-to-one relationships

One-to-many relationships

Many-to-many relationships

Embedding versus references

Applying schema design patterns

The bucket pattern

The attribute pattern

The polymorphic pattern

The extended reference pattern

The approximation pattern

The computed pattern

The outlier pattern

The subset pattern

The document versioning pattern

The schema versioning pattern

The tree pattern

Schema design anti-patterns

Indexes

Determining whether a query used an index

Index types

Single-field indexes

Compound indexes

Multikey indexes

Text search

TTL indexes

Partial indexes

Geospatial indexes

Wildcard indexes

Hidden indexes

Hashed indexes

Clustered indexes

Identifying common queries

Persistent query settings for indexes

Covered queries

Indexing strategies

Summary

Queries

Technical requirements

MongoDB CRUD operations

Basic CRUD with mongosh

Connecting to MongoDB

Creating documents

Reading documents

Updating documents

Deleting documents

Basic CRUD with the Python driver

Installing and connecting to PyMongo

Creating documents

Reading documents

Updating documents

Deleting a document

Bulk operations

Syntax

Aggregations in MongoDB

Introduction to the aggregation framework

Aggregation pipeline example

Benefits of the aggregation framework

Aggregation stages

Compatibility

Common aggregation stages

MongoDB 8.0 aggregation stage enhancements

Advanced aggregation pipelines

Best practices

Code modularity

Streaming and blocking stages of a pipeline

Query shapes

Query settings

Query settings commands

$queryStats statistics

Fields, operands, and aggregation pipelines

New database commands

Collection database commands

Server database commands

Summary

Database Operations

Technical requirements

Monitoring

Why monitor?

Cluster monitoring

Memory metrics

Page faults

Resident memory

Virtual memory

WiredTiger

In-memory storage engine

I/O metrics

Waits and queues

Free disk space

Monitoring replication

Oplog size

Network monitoring

Cursors and connections

Replication opcounters

Working set considerations

Indexes and the working set

Considerations for sharded clusters

Config server health

Data distribution

Locks

Data consistency

MongoDB reporting tools

Local tools

First-party tools

Third-party tools

Monitoring with the Atlas CLI

Common monitoring pitfalls

MongoDB backups

Backing up with Atlas

Self-managed platform backup

Local backups

Consistency requirements

Full versus incremental backup

Backing up with mongodump

Filesystem snapshots

Backing up with cp or rsync

Cluster-to-cluster sync

Common backup pitfalls

Auditing

System logging versus auditing

System logging

Verbosity

Redaction

Logging on managed deployments

Audit logging

Audit log formats

Types of auditable events

Enabling auditing in self-managed deployments

Enabling auditing in Atlas

Audit filters

Database profiling

Viewing and downloading logs

Log rotation

Case study: Auditing for compliance

Troubleshooting auditing

Tools for audit analysis

Summary

Security

Technical requirements

Application security

SCRAM

X.509 certification

Authorization and role-based access control

User-defined roles

Data security

Encryption at rest with key management

Encryption in transit with TLS

Client-Side Field Level Encryption

Queryable Encryption

Comparing CSFLE and Queryable Encryption

$redact pipeline operator

Security in MongoDB deployments

LDAP deprecation

Why deprecation?

OIDC overview

Using OIDC with MongoDB

Kerberos

Network hardening

Summary

MongoDB Atlas

Technical requirements

Setting up your organization

Managing organizations in MongoDB Atlas

Project-level configuration

Understanding clusters

Exploring tools for interacting with MongoDB Atlas

Atlas UI

Atlas CLI

Programmatic access and automation

What is the Atlas Kubernetes Operator?

The power of declarative management

Getting started with the Atlas Kubernetes Operator

Exploring data through the Atlas BI Connector

Benefits of DirectQuery for MongoDB Atlas

Atlas Charts

Enhancing table charts with hyperlinks

Creating charts with Natural Language Mode

Familiar tools

Sizing an Atlas cluster

Storage, RAM, CPU, IOPS, and connections per tier

Storage requirements

Document size calculation

Collection size calculation

Total collection size

Index size

WiredTiger compression

Buffer size

Future growth projections

Additional considerations

RAM requirements

WiredTiger memory allocation

RAM calculation example

IOPS and performance analysis

IOPS provisioning and scaling

Provisioned IOPS for write-heavy workloads

Using monitoring tools to scale effectively

Network throughput and connections

Bandwidth calculation

Connection management

Region selection

Latency optimization

Final cluster selection

Scaling in Atlas

Why is choosing the right scaling strategy so important?

Vertical scaling in Atlas

Trade-offs and limitations

Vertical scaling implementation options

Auto-scaling capabilities

Storage auto-scaling

Cluster tier auto-scaling

Auto-scaling considerations

Horizontal scaling in MongoDB Atlas

Components of a sharded cluster

Shard key selection

Global Clusters for geographic distribution

Administrative considerations

Cost and operational trade-offs

Horizontal versus vertical scaling

Creating a comprehensive scaling strategy

Configuring authentication and authorization

Understanding authentication and authorization

The control plane and data plane

Workforce versus workload

Authentication

Atlas workforce user authentication

Atlas workload user authentication

Database user authentication

Authorization

Role-based access control

Atlas user roles

Database user roles

Custom roles

Securing your Atlas deployments

Why security from the beginning matters

Atlas security tooling: Comprehensive protection

Compliance and standards

Shared responsibility model

Understanding the division of security duties

Encryption in MongoDB Atlas

Encryption in transit

Encryption at rest

Encryption in use

Network security enhancement

Network peering

Private endpoints

IP access list

Auditing capabilities

Audit log

Activity feeds

Using audit logs and activity feeds together

Configuring auditing in Atlas

The compliance connection

Securing your Atlas deployment: Best practices

Security implementation checklist

Deprecating services in Atlas

Serverless clusters

Next steps

Summary

Atlas Search

Technical requirements

Getting started with Atlas Search

Tools to get started with Atlas Search

The mongot

Search Nodes

Why move to dedicated Search Nodes?

Benefits of dedicated Search Nodes

When should you use Search Nodes?

Getting started with Search Nodes

Atlas Search indexes

Field mapping: dynamic versus static

Choosing the right data types

Atlas Search queries

Atlas Search operators and collectors

Compound operator

Search facets

Atlas Vector Search

From keywords to meaning

What are vectors, and why do they matter?

Dense versus sparse

How Atlas Vector Search works

Setting up the environment

Generating vector embeddings with Voyage AI

Understanding embedding models

Leveraging Voyage AI for embeddings

Implementing embedding generation for the movies collection

Vector Search indexes

Understanding the technology behind Vector Search

The evolution to HNSW

Creating a Vector Search index

Understanding similarity functions

Pre-filtering your vector searches

Important considerations and limitations

Performing vector searches with $vectorSearch

Understanding the results

ANN versus ENN: understanding search approaches

Approximate nearest neighbor (ANN) search

Exact nearest neighbor (ENN) search

Optimizing Vector Search performance

Bringing your data to life with hybrid search, RAG, and AI agents

Hybrid search: the best of both worlds

Retrieval-augmented generation (RAG)

AI agents: taking action with your data

Integration ecosystem: build faster with leading AI tools

Summary

Other Books You May Enjoy

Index

Landmarks

Cover

Index

Preface

In today’s fast-moving technology landscape, data sits at the core of how we build smarter applications and deliver world-class experiences to our users. As systems become more interactive and personalized, you need a database that is not only flexible and performant but also deeply aligned with how modern software is built. MongoDB was created to support that vision; from its expressive document model to its intuitive query language, MongoDB delivers developer-first features that streamline the way teams work with data.

Whether you’re a developer, architect, data engineer, or someone supporting modern data applications, this book is your guide to working with MongoDB. It will help you write expressive queries, design efficient data models, secure your deployments, and use advanced features such as aggregation, full-text search, and Atlas automation. Each chapter delivers knowledge and teachings rooted in best practices and real-world use cases.

The content in this book is modular, allowing you to focus on the areas most relevant to your role or project. Newcomers may benefit from reading chapters sequentially to build foundational knowledge, while more experienced readers can jump into topics such as modeling strategies, Atlas automation, or security architecture. The goal throughout is to help you apply MongoDB confidently and effectively to modern application demands.

How this book will help you

This book provides the knowledge and tools to confidently build and scale MongoDB-powered applications. From querying and modeling to aggregation and deployment, each chapter offers practical techniques, clear examples, and useful insights.

You’ll also learn how to monitor performance, implement security best practices, and use the MongoDB Atlas platform for cloud deployments, search features, and simplified operations.

Who this book is for

This book is intended for developers, database professionals, architects, and platform teams who want to understand and use MongoDB effectively. Whether you’re working on web apps, APIs, mobile services, or backend systems, the concepts here will help you structure data, improve performance, and deliver value to your users. Prior experience with MongoDB isn’t required, but familiarity with databases and programming will be helpful.

What this book covers

Chapter 1, Introduction to MongoDB, introduces key concepts, the document model, and use cases.

Chapter 2, MongoDB Architecture, explains core system design principles and how they support scalability and resilience.

Chapter 3, Developer Tools, explores productivity features, IDE integrations, and AI-enhanced development workflows.

Chapter 4, Data Modeling and Index Optimization, covers schema strategies and indexing techniques to support efficient access patterns.

Chapter 5, Queries, shows how to filter, project, and sort data using MongoDB’s expressive query language.

Chapter 6, Database Operations, discusses data operations, deployment practices, and foundational security configurations.

Chapter 7, Security, delves deeper into authentication, authorization, encryption, and compliance strategies.

Chapter 8, MongoDB Atlas, guides you through deploying and managing MongoDB in the cloud, including automation and scaling features.

Chapter 9, Atlas Search, explores platform-native capabilities such as Atlas Search, triggers, and serverless services.

To get the most out of this book

You will require the following software:

Software covered in the book

Operating system requirements

MongoDB version 4.4 or newer

Windows, macOS, or Linux

MongoDB Atlas Shell

Windows, macOS, or Linux

MongoDB Shell

Windows, macOS, or Linux

After reading this book, we encourage you to check out some of the other resources available at https://www.mongodb.com/developer and https://learn.mongodb.com/.

Download the example code files

The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/The-Official-MongoDB-Guide. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781837021970.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and X/Twitter handles. For example: “To disable mirrored reads, you can set the mirrorReads parameter to 0.0.”

A block of code is set as follows:

db.adminCommand( { setParameter: 1, mirrorReads: { samplingRate: 0.0 } } )

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

db.settings.updateOne( { _id: "balancer" }, { $set: { activeWindow: {start: "<start-time>", stop: "<end-time>"} }}, { upsert: true } )

Bold: Indicates a new term, an important word, or words that you see on the screen. For instance, words in menus or dialog boxes appear in the text like this. For example: “Select System info from the Administration panel.”

Warnings or important notes appear like this.

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book or have any general feedback, please email us at [email protected] and mention the book’s title in the subject of your message.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you could report this to us. Please visit http://www.packt.com/submit-errata, click Submit Errata, and fill in the form.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit http://authors.packt.com/.

Share your thoughts

Once you’ve read The Official MongoDB Guide, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.

Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.