Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MongoDB Fundamentals

You're reading from   MongoDB Fundamentals A hands-on guide to using MongoDB and Atlas in the real world

Arrow left icon
Product type Paperback
Published in Dec 2020
Publisher Packt
ISBN-13 9781839210648
Length 748 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (4):
Arrow left icon
Juned Ahsan Juned Ahsan
Author Profile Icon Juned Ahsan
Juned Ahsan
Liviu Nedov Liviu Nedov
Author Profile Icon Liviu Nedov
Liviu Nedov
Amit Phaltankar Amit Phaltankar
Author Profile Icon Amit Phaltankar
Amit Phaltankar
Michael Harrison Michael Harrison
Author Profile Icon Michael Harrison
Michael Harrison
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface
1. Introduction to MongoDB 2. Documents and Data Types FREE CHAPTER 3. Servers and Clients 4. Querying Documents 5. Inserting, Updating, and Deleting Documents 6. Updating with Aggregation Pipelines and Arrays 7. Data Aggregation 8. Coding JavaScript in MongoDB 9. Performance 10. Replication 11. Backup and Restore in MongoDB 12. Data Visualization 13. MongoDB Case Study Appendix

MongoDB Atlas

MongoDB Atlas is the DBaaS offering from MongoDB Inc. It allows you to provision a database on the cloud as a service, which can be used for your applications from anywhere. Atlas uses cloud infrastructures from different cloud vendors. You can choose the cloud vendor on which you want to deploy your database. Like any other managed service, you get the benefits of highly available secured environments with low or no maintenance needed.

MongoDB Atlas Benefits

Let us look at some of the benefits of MongoDB Atlas.

  • Simple Setup: The database setup on Atlas is easy and can be done in just a few steps. Atlas runs a variety of automated tasks behind the scenes to set up your multi-node cluster.
  • Guaranteed Availability: Atlas deploys at least three data nodes or servers per replica set. Each node is deployed in a separate availability zone (Amazon Web Services (AWS)), fault domains (Microsoft Azure), or zones (Google Cloud Platform (GCP)). This allows a highly available setup and continuous uptime in case of outages or routine updates.
  • Global Presence: MongoDB Atlas is available across different regions in the AWS, GCP, and Microsoft Azure clouds. The support for different regions allows you to pick a region closer to you for low latency read and write.
  • Optimal Performance: The founders of MongoDB manage Atlas, and they utilize their expertise and experience to keep the databases in Atlas running optimally. Also, single-click upgrades are available for upgrading to the latest versions of MongoDB.
  • Highly Secured: Security best practices are implemented by default, such as a separate VPC (virtual private cloud), network encryption, access controls, and firewalls to restrict access.
  • Automated Backups: You can configure automated backups with customizable schedules and data retention policies. Secure backups and restores are available for switching between different versions of your database.

Cloud Providers

MongoDB Atlas currently supports three cloud providers, namely AWS, GCP, and Microsoft Azure.

Availability Zones

Availability Zones (AZs) are a group of physical data centers within close proximity, equipped with computational, storage, or networking resources.

Regions

A region is a geographical area, for example, Sydney, Mumbai, London, and so on. A region generally consists of two or more AZs. The AZs are generally in different cities/towns away from each other, to provide fault tolerance in case of any natural disasters. Fault tolerance is the ability of a system to keep running when something goes wrong in one portion of the system. In terms of AZs, if one AZ goes down due to some reason, another AZ should still be able to serve the operations.

MongoDB Supported Regions and Availability Zones

MongoDB Atlas allows you to deploy your database in a multi-cloud global infrastructure from AWS, GCP, and Azure. It allows MongoDB to support a vast number of regions and AZs. Also, the number of supported regions and AZs keeps growing as cloud providers keep adding to them. Follow these links from the official MongoDB website about cloud providers' region support:

Atlas Tiers

To build a database cluster in MongoDB Atlas, you need to select a tier. A tier is a level of database power that you get from your cluster. When you provision your database in Atlas, you are given two parameters: RAM and storage. Depending on your selection of these parameters, an appropriate amount of database power is provisioned. The cost of your cluster is linked to the selection of RAM and storage; a higher selection means a higher cost and a lower selection means a lower cost.

M0 is the free tier available in MongoDB Atlas, which gives you shared RAM with storage of 512 MB. It is the tier that we will be using for our learning purposes. The free tier is not available in all regions, so if you do not find it in your region, select the closest free tier region. The proximity of your database determines the latency for your operations.

Selecting a tier requires an understanding of your database usage and how much you would like to spend. Under provisioned databases can exhaust your application's capacity at peak usage and can lead to application errors. Overprovisioned databases can help your application perform well but are more expensive. One of the advantages of using a cloud database is that you can always modify your cluster size as per your needs. But you still need to find what is the optimal capacity for your day-to-day database use. Determining the maximum number of concurrent connections is a critical decision factor that can help you choose the appropriate MongoDB Atlas tier for your use case. Let us look at the different tiers available:

Figure 1.2: MongoDB Atlas tier configuration

Figure 1.2: MongoDB Atlas tier configuration

MongoDB Atlas Pricing

Capacity planning is essential but estimating the cost of your database cluster is important too. We learned that an M0 cluster is free, with minimal resources, making it ideal for prototyping and learning purposes. For the paid cluster tiers, Atlas charges you on an hourly basis. The total cost is comprised of multiple factors, such as the type and number of servers. Let us look at an example to understand the cost estimation of an M30 type replica set (three servers) on Atlas.

Cluster Cost Estimation

Let us try to understand how to estimate the cost of your MongoDB Atlas cluster. Identify the cluster requirements as follows:

  • Machine type: M30
  • Number of servers: 3 (replica set)
  • Running time: 24 hours a day
  • Estimation time period: 1 month

Once we have identified our requirements, the estimated cost can be calculated as follows:

  • Cost of running a single M30 server per hour: $0.54
  • Number of hours a server will run: 24 (hours) x 30 (days) = 720
  • Cost of a single server for a month: 720 x 0.54 = $388.8
  • Cost of running the three-server cluster: 388.8 x 3 = $1166.4

So, the total cost should come down to $1166.4.

Note

Apart from the running cost of your cluster, you should consider the cost of additional services such as backups, data transfer, and support contracts.

Let us implement our learning in an example scenario through the following exercise.

Exercise 1.01: Setting Up a MongoDB Atlas Account

MongoDB Atlas offers you free registration to set up a free cluster. In this exercise, you will create an account by executing the following steps:

  1. Go to https://www.mongodb.com and click Start free. The following window appears:
    Figure 1.3: MongoDB Atlas home page

    Figure 1.3: MongoDB Atlas home page

  2. You can sign up using your Google account or by providing your details manually as can be seen from the following screen. Provide your usage, Your Work Email, First Name, Last Name, and Password details in the respective fields, select the checkbox to agree to the terms of service and click Get started free.
    Figure 1.4: The Get started page

Figure 1.4: The Get started page

The following window appears in which you can enter your organization and project details:

Figure 1.5: Page to enter the organization and project details

Figure 1.5: Page to enter the organization and project details

Next, you should see the following page, which means your account has been successfully created:

Figure 1.6: Confirmation page

Figure 1.6: Confirmation page

In this exercise, you successfully created your MongoDB account.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime