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 now! 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
Conferences
Free Learning
Arrow right icon
Mastering MongoDB 7.0
Mastering MongoDB 7.0

Mastering MongoDB 7.0: Achieve data excellence by unlocking the full potential of MongoDB , Fourth Edition

Arrow left icon
Profile Icon Marko Aleksendrić Profile Icon Rajesh Nair Profile Icon Elie Hannouch Profile Icon Malak Abu Hammad Profile Icon Leandro Domingues Profile Icon Arek Borucki Profile Icon Rachelle Palmer +3 more Show less
Arrow right icon
$59.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jan 2024 434 pages 4th Edition
eBook
$59.99
Paperback
$74.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Marko Aleksendrić Profile Icon Rajesh Nair Profile Icon Elie Hannouch Profile Icon Malak Abu Hammad Profile Icon Leandro Domingues Profile Icon Arek Borucki Profile Icon Rachelle Palmer +3 more Show less
Arrow right icon
$59.99
Full star icon Full star icon Full star icon Full star icon Full star icon 5 (1 Ratings)
eBook Jan 2024 434 pages 4th Edition
eBook
$59.99
Paperback
$74.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$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
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

Mastering MongoDB 7.0

Introduction to MongoDB

MongoDB, the most popular document database, is a NoSQL, non-relational key-value store, a JSON database, and more. It is a robust, feature-rich developer data platform with various built-in features that you need for modern applications, such as machine learning and AI capabilities, streaming, functions, triggers, serverless, device sync, and full-text search.

Though MongoDB is non-relational, it can easily handle relational data. It offers courses, tutorials, and documentation at learn.mongodb.com on how to best model and handle that data, even while using the document format.

Who uses MongoDB

10 years ago, the use of MongoDB was somewhat niche. It was a young database with compelling features for developers like you. Now, in 2023, MongoDB is used by a myriad of varied industries, and its use cases span across all kinds of situations and types of data stored. Some of the largest banks, automakers, government agencies, and gaming companies in the world use MongoDB for their production applications. The most famous users of MongoDB are Coinbase, Epic Games, Morgan Stanley, Adobe, Tesla, Canva, Ulta Beauty, Cathay Pacific, Dongwha, and Vodafone.

The MongoDB Atlas platform has millions of users, all of whom trust that their data will be managed safely and effectively in the cloud. This popularity has taken MongoDB to great heights, not just in terms of its growth and value as a company but also in terms of its raw developer mindshare. As of 2023, one in four developers uses MongoDB extensively in production. This ratio is much larger in other developer communities such as Go and JavaScript (approximately 40%).

Why developers love MongoDB

Along with its versatality, and robust features, MongoDB is the preferred choice for several reasons, such as:

  • Flexibility and schema-less: Unlike traditional relational databases, MongoDB allows you to store and retrieve data without strict schemas or predefined structures. This flexibility is particularly useful when data evolves over time or when you are dealing with unstructured or semi-structured data.
  • Scalability and performance: MongoDB is highly scalable and performs exceptionally well, making it suitable for both large-scale applications and personal projects. MongoDB Atlas provides a free-forever tier for side projects.
  • Rich query language: MongoDB offers a powerful query language and indexing capabilities, simplifying common operations such as findOne and updateOne.
  • Developer-friendly data format: Data in MongoDB closely resembles objects in popular programming languages, reducing data mapping complexities and expediting development.
  • Simplicity and quick start: MongoDB's simplicity and hassle-free setup makes it easy to adapt. No complex sales processes or licensing hassles are involved.

What attracts most developers is the simplicity of working with MongoDB on a daily basis, in particular, the seamless experience of creating, updating, and interacting with data. For example, consider a Python developer attempting to insert a document, query that document, and receive a set of results, using the following code:

from pymongo import MongoClient
# Connect to MongoDB
client = MongoClient('mongodb://localhost:27017/')
db = client['mydatabase']  # Specify the database name
collection = db['mycollection']  # Specify the collection name
# Create a document to be inserted
document = {
    'name': 'Jane Doe',
    'age': 30,
    'email': 'janedoe@example.com'
}
# Insert the document into the collection
result = collection.insert_one(document)
# Check if the insertion was successful
if result.acknowledged:
    print('Document inserted successfully.')
    print('Inserted document ID:', result.inserted_id)
else:
    print('Failed to insert document.')

Note that the developer creates a dictionary representing the document to be inserted. In this case, it contains the name, age, and email details. The developer doesn't need to create an ID for the document, because MongoDB automatically creates a unique identifier on each document.

To retrieve this document, you can filter the query by using any of the document's field individually, or in combination. Let's see that in action:

from pymongo import MongoClient
# Connect to MongoDB
client = MongoClient('mongodb://localhost:27017/')
db = client['mydatabase']  # Specify the database name
collection = db['mycollection']  # Specify the collection name
# Retrieve documents based on specific conditions
query = {
    'age': {'$gte': 29},  # Retrieve documents where age is greater than or equal to 29
}
documents = collection.find(query)
# Iterate over the retrieved documents
for document in documents:
    print(document)

Pretty simple! The preceding example demonstrates how you can use a MongoDB query operator such as $gte (greater than or equal to) to filter your query. But the real magic happens when the document is returned. When MongoDB returns a document, it will be represented as a Python dictionary. Each field in the document is a key-value pair within the dictionary, similar to the following example:

{
    '_id': ObjectId('60f5c4c4543b5a2c7c4c73a2'),
    'name': 'Jane Doe',
    'age': 30,
    'email': 'janedoe@example.com'
}

MongoDB has a suite of language libraries and drivers that act as a translation layer between the client and server, intercepting each operation and translating it into MongoDB's query language. With this, you can interact with the data using your native programming language in a purely idiomatic way.

Alongside the other offerings of the MongoDB Atlas developer data platform, it truly abstracts away the difficulties of working with a database, and instead allows you to interact with data purely via your code and IDE. This is infinitely preferable while using a separate database shell, database UI, and other database-specific tools. Since MongoDB Atlas offers a completely managed MongoDB database, you can set up and register via a command-line interface.

At its heart, the mission of MongoDB is to be a powerful database for developers, and its features are tuned to the programming language communities and framework integrations, rather than to database administration tools. This will become more apparent in the subsequent chapters, where you'll learn more about MongoDB Atlas, Atlas Vector Search, full-text search, and features such as aggregation—all through the lens of a developer.

By the end of this book, you'll learn how effective these tools can be and make database management simpler!

Efficiency of the inherent complexity of MongoDB databases

The most interesting part of the modern database is understanding its architecture and why it's built that way. Fundamentally, MongoDB is a distributed system. The database server itself was originally built with the anticipation that most users would run it with a default configuration—replica set, sometimes also referred to as a cluster. When you explore this architecture in-depth, you'll notice the true complexities.

By default, replica set of MongoDB is a three-node configuration. All three nodes are data-bearing, which means that there is a complete copy of the database available on each node. Each database is hosted on a separate instance or host, which can be in the same availability zone, data center, or region. This default configuration is to ensure both redundancy and high availability. Chapter 2, The MongoDB Architecture will discuss replica sets in more detail.

If one of the instances becomes unresponsive or unavailable, a healthy node is promoted to become the primary node. This failover between members occurs automatically, and there's no impact on operations for the users of the database. This process considers many different factors, including node availability, data freshness, and responsiveness. This election process and protocol, while simple to understand at a high-level, is very nuanced. But since the operations continue without interruption, you hardly know or understand these details.

How is this possible?

Behind the scenes, write operations to MongoDB are propagated from the primary node to the secondary nodes via a process called replication. The best way to explain replication is with the example of a single write to the database. An inbound write from the client application (your app) will be first directed to the primary node. That primary node will apply the write to its copy of the database. Then, the write is recorded in the operations log (oplog), which is tailed by secondary nodes.

Replication in MongoDB is based on the RAFT consensus protocol. One particular example of how this implementation varies is leader elections. In the traditional RAFT protocol, leader and primary node election occurs through a combination of randomized election timeouts and message exchanges. In MongoDB, there are settings for node priority. This priority is considered along with data freshness and response time when electing a primary node.

It is often true that the write operation is not written simultaneously to all nodes—there is a lag heavily influenced by factors such as network latency, the distance between nodes, hardware configuration, and workload. If one of the mongod nodes falls behind, it will catch up or resync itself when it is able to do so using the oplog to determine the gaps in its operations. The MongoDB system monitors the replication lag between nodes to track this metric and assess whether the delay between primary and secondary nodes is acceptable, and if not, takes necessary action. This process is unique among databases as well.

This default configuration of MongoDB is a replica set with three members, where replication of data between nodes and failover between nodes are all handled automatically. This configuration is both durable and highly available, which makes it easy to use. For developers who require larger, global deployments, MongoDB has a sharded cluster model. The first thing to understand is that a sharded cluster consists of replica sets. It is a way of further dividing your data into effectively replicated partitions.

Figure 1.1: Replicated partitions set with primary and secondary nodes

If you require a global deployment with multiple terabytes of data, get started with Chapter 2, The MongoDB Architecture. It will cover how to split data, how to migrate data between regions or shards, how to marry data from multiple regions for analytics, and the performance of sharded cluster architectures.

Summary

MongoDB is a simple yet powerful database. It abstracts away many of the more complicated implementation details so that you can focus on building applications. It's easy to get started with and offers a powerful, idiomatic developer experience that allows you to interact with the database, exclusively in the programming language of your choice, via your IDE.

The rest of the book details how powerful and flexible MongoDB is, the new features in MongoDB 7.0, and how you can use it to your advantage. Besides being a great database for web applications, transactional data, flexible schemas, and high-performance workloads, it is also a great database for learning through hands-on experience and building proofs of concept.

In the next chapter, you'll see how replication and sharding can help increase reliability and availability for your applications.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • 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

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.

Who is this book 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.

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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 05, 2024
Length: 434 pages
Edition : 4th
Language : English
ISBN-13 : 9781835463192
Vendor :
MongoDB
Category :
Languages :
Concepts :
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
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Jan 05, 2024
Length: 434 pages
Edition : 4th
Language : English
ISBN-13 : 9781835463192
Vendor :
MongoDB
Category :
Languages :
Concepts :
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

Frequently bought together


Stars icon
Total $ 199.97
Practical MongoDB Aggregations
$74.99
Observability with Grafana
$49.99
Mastering MongoDB 7.0
$74.99
Total $ 199.97 Stars icon

Table of Contents

19 Chapters
Chapter 1: Introduction to MongoDB Chevron down icon Chevron up icon
Chapter 2: The MongoDB Architecture Chevron down icon Chevron up icon
Chapter 3: Developer Tools Chevron down icon Chevron up icon
Chapter 4: Connecting to MongoDB Chevron down icon Chevron up icon
Chapter 5: CRUD Operations and Basic Queries Chevron down icon Chevron up icon
Chapter 6: Schema Design and Data Modeling Chevron down icon Chevron up icon
Chapter 7: Advanced Querying in MongoDB Chevron down icon Chevron up icon
Chapter 8: Aggregation Chevron down icon Chevron up icon
Chapter 9: Multi-Document ACID Transactions Chevron down icon Chevron up icon
Chapter 10: Index Optimization Chevron down icon Chevron up icon
Chapter 11: MongoDB Atlas: Powering the Future of Developer Data Platforms Chevron down icon Chevron up icon
Chapter 12: Monitoring and Backup in MongoDB Chevron down icon Chevron up icon
Chapter 13: Introduction to Atlas Search Chevron down icon Chevron up icon
Chapter 14: Integrating Applications with MongoDB Chevron down icon Chevron up icon
Chapter 15: Security Chevron down icon Chevron up icon
Chapter 16: Auditing Chevron down icon Chevron up icon
Chapter 17: Encryption Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
CHANDA RAJ KUMAR Feb 20, 2024
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very Useful from basics to advanced concepts .. highly recommended
Feefo Verified review Feefo image
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.