Mastering MongoDB 7.0 - Fourth Edition

Book description

Gain MongoDB expertise and discover advanced queries and Atlas insights with this ultimate guide to version 7.0

Key Features

  • Enhance your proficiency in advanced queries, aggregation, and optimized indexing to achieve peak MongoDB performance
  • Monitor, back up, and integrate applications effortlessly with MongoDB Atlas
  • Implement security thorough RBAC, auditing, and encryption to ensure comprehensive data protection and privacy
  • Purchase of the print or Kindle book includes a free PDF eBook

Book Description

Mastering MongoDB 7.0 explores the latest version of MongoDB, an exceptional NoSQL database solution that aligns with the needs of modern web applications. This book starts with an informative overview of MongoDB’s architecture and developer tools, guiding you through the process of connecting to databases seamlessly.

This MongoDB book explores advanced queries in detail, including aggregation pipelines and multi-document ACID transactions. It delves into the capabilities of the MongoDB Atlas developer data platform and the latest features, such as Atlas Vector Search, and their role in AI applications, enabling developers to build applications with the scalability and performance that today’s organizations need. It also covers the creation of resilient search functionality using MongoDB Atlas Search. Mastering MongoDB 7.0’s deep coverage of advanced techniques encompasses everything from role-based access control (RBAC) to user management, auditing practices, and encryption across data, network, and storage layers.

By the end of this book, you’ll have developed the skills necessary to create efficient, secure, and high-performing applications using MongoDB. You’ll have the confidence to undertake complex queries, integrate robust applications, and ensure data security to overcome modern data challenges.

What you will learn

  • Execute advanced MongoDB queries for intricate data insights
  • Harness the power of aggregation pipelines to transform data
  • Ensure data integrity with multi-document ACID transactions
  • Optimize query performance using strategic indexing techniques
  • Navigate MongoDB Atlas seamlessly for monitoring and backups
  • Enable robust search functionality with Atlas Search
  • Master RBAC, user management, and data encryption for security
  • Implement auditing practices for transparency and accountability

Who this book is for

This book is for developers with an intermediate skill level who aim to become MongoDB experts. Working knowledge of MongoDB is recommended to gain the most from this guide. Ideal for database administrators, app developers, and software engineers, this book will assist you in developing advanced skills to conquer intricate data tasks.

Table of contents

  1. Note from Author
  2. Preface
    1. How will this book help you?
    2. Who is this book for?
    3. What does this book cover?
    4. To get the most out of this book
    5. Download the example code files
    6. Conventions used
    7. Get in touch
    8. Download a free PDF copy of this book
  3. Chapter 1: Introduction to MongoDB
    1. Who uses MongoDB
    2. Why developers love MongoDB
    3. Efficiency of the inherent complexity of MongoDB databases
      1. How is this possible?
    4. Summary
  4. Chapter 2: The MongoDB Architecture
    1. Replication vs sharding
    2. Replication
      1. Replica set elections
      2. Replica set oplog
      3. Replica set deployment architectures
      4. Write concern
      5. Read preference
      6. Read concern
      7. Replication methods
    3. Sharding
      1. Why do you need sharding?
      2. Key elements of a sharded cluster
      3. Microsharding
      4. Advantages of sharding
      5. Data distribution
      6. Chunks
      7. Chunk administration
      8. Querying sharded data
      9. Sharding methods
    4. New sharded cluster features in MongoDB 7.0
      1. Shard key advisor commands
      2. AutoMerger
      3. Command support without shard keys
    5. Summary
  5. Chapter 3: Developer Tools
    1. Technical requirements
    2. Introduction to developer tools
      1. Categories of developer tools
    3. MongoDB Shell
      1. Installation
      2. Connecting to a MongoDB deployment using mongosh
      3. mongosh vs legacy shell
      4. Key features of mongosh
      5. Use cases for mongosh
      6. Best practices for using mongosh
    4. MongoDB CLI
      1. Installation
      2. Configuration
      3. Working with MongoDB CLI
      4. mongocli auth
      5. Key features of MongoDB CLI
      6. Use cases for MongoDB CLI
      7. Best practices for MongoDB CLI
    5. MongoDB Compass
      1. Installation
      2. Configuration
      3. Visually explore data using Compass
      4. Key features of MongoDB Compass
      5. Use cases for MongoDB Compass
      6. Best practices for MongoDB Compass
    6. MongoDB for VS Code
      1. Installation
      2. Explore data using Playground
      3. Use Terraform to create an Atlas cluster
      4. Key features
      5. Use cases for the MongoDB for VS Code extension
      6. Best practices for the MongoDB for VS Code extension
    7. Summary
  6. Chapter 4: Connecting to MongoDB
    1. Connecting methods
      1. Connecting using Ruby
      2. Connecting using Python
      3. Connecting using PHP
      4. Connecting using Node.js
      5. Connecting using TypeScript
    2. Summary
  7. Chapter 5: CRUD Operations and Basic Queries
    1. Technical requirements
    2. MongoDB CRUD operations
      1. CRUD using mongosh
      2. Scripting for mongosh
      3. Batch inserts using mongosh
      4. Batch operations using mongosh
    3. CRUD using the Ruby driver
      1. Connecting to a database
      2. Creating documents
      3. Reading data
      4. Chaining operations in find()
      5. Nested operations
      6. Batch operations
      7. Mongoid ODM
    4. CRUD using the Python driver
      1. Inserting documents
      2. Finding documents
      3. Updating documents
      4. Deleting documents
    5. Regular expressions
    6. Administration
      1. currentOp() and killOp()
      2. collMod
    7. Secure access to MongoDB
      1. Authentication and authorization
    8. MongoDB Stable API
    9. Summary
  8. Chapter 6: Schema Design and Data Modeling
    1. Schema design for relational databases
      1. Normal forms
    2. Schema design for MongoDB
    3. Data modeling in MongoDB
      1. Document structure
      2. Embedded data
      3. References
      4. Denormalization
      5. BSON and its data types
    4. Design considerations and best practices for MongoDB modeling
      1. Read-write ratio
    5. Design patterns and schema design
    6. Summary
  9. Chapter 7: Advanced Querying in MongoDB
    1. Introduction to the aggregation framework
    2. Benefits of aggregation in MongoDB
    3. Aggregation stages
    4. Query Techniques
      1. Logical and comparison operators
      2. Array querying and manipulation
      3. Array field projection techniques
    5. Indexes and query optimization
      1. Benefits of using indexes
      2. Types of index
    6. Geospatial features in MongoDB
      1. GeoJSON objects
      2. Geospatial indexes
      3. Geospatial operators
    7. Summary
  10. Chapter 8: Aggregation
    1. Technical requirements
    2. MongoDB aggregation framework
      1. Modularity and composability
      2. Stages
      3. Aggregation expressions
    3. Basic aggregation operators
      1. Bitwise operators in aggregation
      2. Array expression operators
      3. The "power" array operators: $map and $reduce
      4. Other types of aggregations
    4. Best practices
      1. Code modularity
      2. Query optimization
      3. Streaming and blocking stages of a pipeline
      4. Sharded cluster considerations
    5. Summary
  11. Chapter 9: Multi-Document ACID Transactions
    1. Why are transactions useful?
    2. ACID properties
      1. Atomicity
      2. Consistency
      3. Isolation
      4. Durability
    3. MongoDB implementation of ACID
      1. Read and write concerns in transactions
      2. Transaction limitations
    4. Best practices
    5. Summary
  12. Chapter 10: Index Optimization
    1. Introduction to indexes
      1. Creating an index
    2. Index types
      1. Single-field indexes and indexing embedded documents
      2. Compound indexes
      3. Multikey indexes
      4. Covered queries
      5. Hashed index
      6. Text indexes
      7. Atlas Search Indexes
      8. TTL indexes
      9. Partial indexes
      10. Geospatial indexes
      11. Wildcard indexes
      12. Hidden indexes
      13. Compound wildcard indexes
    3. Best practices for index optimization
    4. Summary
  13. Chapter 11: MongoDB Atlas: Powering the Future of Developer Data Platforms
    1. Understanding MongoDB Atlas as a database-as- a-service
      1. Hosted database
      2. Secure by default
      3. Monitoring and alerting
      4. Back up, restore, and archive
      5. Automation
    2. Atlas developer data platform
    3. Atlas Vector Search and its role in AI applications
      1. What does vector search entail?
      2. What is Atlas Vector Search?
      3. Semantic search and vectors
      4. KNN, ANN, and vector embeddings
      5. How to use Atlas Vector Search
      6. Atlas Search
    4. Atlas Application Services
      1. What is Atlas Application Services?
      2. Key features
      3. How to use Atlas Application Services
    5. Atlas Data API
      1. Security and authorization
      2. Use cases
      3. How to use the Atlas Data API
    6. Atlas Data Lake
      1. Data storage and optimization
      2. How to use Atlas Data Lake
    7. Atlas Data Federation
      1. Data processing
      2. Key features
      3. How to use Atlas Data Federation
    8. Atlas Stream Processing (preview)
      1. Operational mechanism
      2. Key features
      3. Setting up a stream processor
    9. Atlas SQL Interface
      1. How to use the Atlas SQL Interface
    10. MongoDB Atlas Charts
      1. How to use Atlas Charts
    11. Operational integrations: The Atlas Kubernetes Operator
      1. What is the Atlas Kubernetes Operator?
      2. How to use the Atlas Kubernetes Operator
    12. Atlas CLI
      1. How to use the Atlas CLI
      2. Capabilities of the Atlas CLI
    13. Summary
  14. Chapter 12: Monitoring and Backup in MongoDB
    1. Monitoring in MongoDB
      1. Monitoring clusters
      2. Why monitor in MongoDB?
    2. What should you monitor?
      1. Page fault
      2. Resident memory
      3. Virtual and mapped memory
      4. Working set
      5. Track free disk space
      6. Monitoring replication
      7. Oplog size
      8. Network monitoring
      9. Cursors and connections
      10. Document metrics
    3. Monitoring memory usage in WiredTiger
    4. Tracking page faults
      1. Tracking B-tree misses
      2. I/O wait
      3. Read and write queues
    5. Working set calculations
      1. Why is the working set crucial?
      2. Estimate the working set size
      3. Importance of indexes in the working set
    6. MongoDB reporting tools overview
      1. Utilities
      2. Commands
    7. Hosted monitoring tools overview
      1. Cluster backups
    8. MongoDB backup methods
      1. Cloud-based backup solutions
      2. On-premises backup solutions
      3. Using filesystem snapshots for MongoDB backups
      4. Consistency requirements
      5. Backups using mongodump
      6. Backing up with cp or rsync
      7. Backup and restore on EC2
      8. Backup with queues
      9. Incremental backups
    9. Common mistakes and pitfalls in MongoDB monitoring and backup
    10. Summary
  15. Chapter 13: Introduction to Atlas Search
    1. MongoDB Atlas Search
      1. Feature overview
      2. Version requirements for Atlas Search features
      3. Atlas Search architecture
    2. Technical overview of Atlas Search indexes
      1. Index creation and management
      2. Atlas Search queries
      3. Atlas Search query operators and collectors
      4. Query execution in Atlas Search
      5. Relevance scoring in Atlas Search
      6. Atlas Search Nodes
      7. Atlas Search index management
      8. Search query analysis
      9. Troubleshooting Atlas Search errors
    3. Apache Lucene
      1. Apache Software Foundation
      2. Atlas Search and integration with Apache Lucene
    4. Summary
  16. Chapter 14: Integrating Applications with MongoDB
    1. Technical requirements
    2. Integrating applications in MongoDB
    3. The MongoDB Kubernetes Operator
      1. Installation
      2. Deploy and configure MongoDB using the Kubernetes Operator
      3. The Atlas Kubernetes Operator
      4. The Enterprise Kubernetes Operator
    4. Integrating Terraform with MongoDB
      1. Installation
      2. Configuring a MongoDB cluster on Atlas using Terraform
    5. Using Vercel with MongoDB
      1. Building a web application with Vercel and MongoDB
      2. Configuring MongoDB Atlas with Vercel
      3. Disconnecting the Vercel integration
    6. Integrating Datadog with MongoDB
      1. Configuring Datadog
      2. Integrating MongoDB Atlas with Datadog
    7. Integrating Prometheus with MongoDB
      1. Configuring Prometheus
      2. Integrating MongoDB Atlas with Prometheus
    8. Integrating webhooks with MongoDB
      1. Configuring webhooks with MongoDB
      2. Integrating MongoDB with alerting applications
      3. Atlas integrations for webhooks
      4. Microsoft Teams integration
    9. PagerDuty integration
      1. Slack integration
      2. Splunk On-Call integration
      3. Opsgenie integration
      4. Integrating MongoDB with Confluent
      5. Integrating MongoDB with Postman
    10. Summary
  17. Chapter 15: Security
    1. Authentication methods
      1. SCRAM
      2. x.509
      3. LDAP
      4. Kerberos
    2. Role-based access control (RBAC)
      1. Knowing about resources, actions, and roles
      2. Role hierarchy
      3. Managing roles
      4. Access restrictions
    3. Summary
  18. Chapter 16: Auditing
    1. Auditing and logging in MongoDB
    2. Types of auditable events
    3. Enable auditing in MongoDB
      1. Audit filters
      2. Enable auditing in MongoDB Atlas
      3. View and download MongoDB logs
    4. Case study: The role of auditing in compliance
    5. Troubleshoot auditing issues in MongoDB
      1. How to identify and address issues in auditing using MongoDB
      2. Tools for MongoDB audit record analysis
    6. Summary
  19. Chapter 17: Encryption
    1. Encryption types
      1. Certificates
    2. Encryption in-transit
      1. How it works
      2. Configure TLS for MongoDB
    3. Encryption at rest
      1. Encryption at rest in MongoDB
      2. Configure encryption at rest for MongoDB
    4. Client-side encryption
      1. When is CSFLE used
      2. How it works
      3. Configure MongoDB
      4. Restrictions and considerations
      5. Queryable Encryption
    5. Summary
  20. Index
    1. Why subscribe?
  21. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Download a free PDF copy of this book

Product information

  • Title: Mastering MongoDB 7.0 - Fourth Edition
  • Author(s): Marko Aleksendrić, Arek Borucki, Leandro Domingues, Malak Abu Hammad, Elie Hannouch, Rajesh Nair, Rachelle Palmer
  • Release date: January 2024
  • Publisher(s): Packt Publishing
  • ISBN: 9781835460474