MongoDB Complete Guide: Develop Strong Understanding of Administering MongoDB, CRUD Operations, MongoDB Commands, MongoDB Compass, MongoDB Server, MongoDB Replication and MongoDB Sharding (English Edition)
By Manu Sharma
()
About this ebook
Topics such as installation and configuration of the MongoDB server, MongoDB commands, MongoDB Shell methods, and data types in MongoDB are covered in detail.
You will practice how to perform MongoDB CRUD operations, indexing, MongoDB query selectors, projection in MongoDB and projection operators as well as aggregation in a very detailed and step-by-step manner. You learn how to work with MongoDB Compass and some of the advanced MongoDB topics like managing and administering MongoDB, managing the MongoDB process, monitoring and diagnosing MongoDB, backup and restore, MongoDB security, replication and sharding.
Related to MongoDB Complete Guide
Related ebooks
Learn MongoDB in 24 Hours Rating: 5 out of 5 stars5/5Node.JS Guidebook: Comprehensive guide to learn Node.js Rating: 0 out of 5 stars0 ratingsInstant MongoDB Rating: 0 out of 5 stars0 ratingsMongoDB High Availability Rating: 5 out of 5 stars5/5Mongoose for Application Development Rating: 5 out of 5 stars5/5MariaDB High Performance Rating: 0 out of 5 stars0 ratingsMastering Hibernate Rating: 0 out of 5 stars0 ratingsLearning Windows Server Containers Rating: 0 out of 5 stars0 ratingsLinux, Apache, MySQL, PHP Performance End to End Rating: 5 out of 5 stars5/5Mastering MariaDB Rating: 0 out of 5 stars0 ratingsMastering JavaScript Single Page Application Development Rating: 0 out of 5 stars0 ratingsReact Projects: Build 12 real-world applications from scratch using React, React Native, and React 360 Rating: 0 out of 5 stars0 ratingsGet Programming with Go Rating: 5 out of 5 stars5/5DynamoDB Cookbook: Over 90 hands-on recipes to design Internet scalable web and mobile applications with Amazon DynamoDB Rating: 0 out of 5 stars0 ratingsDeploying Node.js Rating: 5 out of 5 stars5/5MongoDB Complete Self-Assessment Guide Rating: 0 out of 5 stars0 ratingsAdvanced Web Development with React: SSR and PWA with Next.js using React with advanced concepts Rating: 0 out of 5 stars0 ratingsHands-On Microservices with Kubernetes: Build, deploy, and manage scalable microservices on Kubernetes Rating: 5 out of 5 stars5/5Mastering React Test-Driven Development: Build rock-solid, well-tested web apps with React, Redux and GraphQL Rating: 0 out of 5 stars0 ratingsThe Art of Docker: Streamline App Development and Deployment with Containerization (Computer Programming) Rating: 0 out of 5 stars0 ratingsReact Components Rating: 0 out of 5 stars0 ratingsLearning Elasticsearch 7.x: Index, Analyze, Search and Aggregate Your Data Using Elasticsearch (English Edition) Rating: 0 out of 5 stars0 ratingsHands-on React Native Rating: 1 out of 5 stars1/5ReactJS for Jobseekers: The Only Guide You Need to Learn React and Crack Interviews (English Edition) Rating: 0 out of 5 stars0 ratings
Enterprise Applications For You
QuickBooks 2023 All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsMicrosoft Excel Formulas: Master Microsoft Excel 2016 Formulas in 30 days Rating: 4 out of 5 stars4/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Notion for Beginners: Notion for Work, Play, and Productivity Rating: 4 out of 5 stars4/5Agile Project Management: Scrum for Beginners Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Microsoft Excel 365 Bible Rating: 0 out of 5 stars0 ratingsExcel Formulas and Functions 2020: Excel Academy, #1 Rating: 4 out of 5 stars4/5Learning Microsoft Endpoint Manager: Unified Endpoint Management with Intune and the Enterprise Mobility + Security Suite Rating: 0 out of 5 stars0 ratingsExcel All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsExcel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsBitcoin For Dummies Rating: 4 out of 5 stars4/550 Useful Excel Functions: Excel Essentials, #3 Rating: 5 out of 5 stars5/5Excel 2019 Bible Rating: 5 out of 5 stars5/5Microsoft Teams For Dummies Rating: 0 out of 5 stars0 ratingsExcel Power Pivot and Power Query For Dummies Rating: 3 out of 5 stars3/5Excel 2019 For Dummies Rating: 3 out of 5 stars3/5Microsoft Word Guide for Success: Achieve Efficiency and Professional Results in Every Document [IV EDITION] Rating: 5 out of 5 stars5/5Excel 2016 For Dummies Rating: 4 out of 5 stars4/5Excel 2021 Rating: 4 out of 5 stars4/5CompTIA Project+ Study Guide: Exam PK0-005 Rating: 0 out of 5 stars0 ratingsExcel VBA Programming For Dummies Rating: 4 out of 5 stars4/5Microsoft Copilot For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for MongoDB Complete Guide
0 ratings0 reviews
Book preview
MongoDB Complete Guide - Manu Sharma
CHAPTER 1
Introduction to MongoDB
This chapter covers the introduction to MongoDB and its architecture it will cover the basics and key terms of MongoDB in a manner that is easier for a beginner to understand. This chapter also gives an introduction to the concepts of document-based databases and NoSQL databases and how these are different from SQL-based databases. We will also cover the MongoDB architecture in a very simple manner with the help of easy-to-understand diagrams. In the last topic, we will cover the core concepts and vocabulary of MongoDB and compare these terms with respect to SQL-based databases.
Structure
In this chapter, we will discuss the following topics:
Introduction to MongoDB and its architecture
Basics and key terms of MongoDB
Introduction to the concept of document-based databases and NoSQL databases
Difference between the NoSQL databases and SQL based databases
The MongoDB architecture overview
Core concepts and vocabulary of the MongoDB
Objectives
After studying this unit, you should be able to understand what exactly is MongoDB and also understand the basics of MongoDB
Understand what are NoSQL databases
Compare between MongoDB and other databases
Introduction
MongoDB is one of the top most popular modern databases which is now widely used for building modern day applications. It is different from traditional RDBMS (Relational Database Management Systems) and it is categorized as NoSQL database because of the flexibility of schema which it provides. MongoDB is easy to use and the data is stored in the JSON (JavaScript Object Notation) like format which stores data in key-value pair and it is very easy for developers while they work on database related queries.
Simple to use, Flexible, Powerful, Scalable and Development Friendly are some of key reasons behind the popularity of MongoDB.
The definition of MongoDB
The best way to define MongoDB is from two main sources. The first is the official website of the creators of MongoDB, MongoDB Inc., and the other is Wikipedia.
Let's see how MongoDB is defined by the creators of MongoDB (MongoDB Inc.) and Wikipedia and let us go through these two definitions one-by-one.
According to the official website, MongoDB Inc. MongoDB is a general-purpose, document-based, distributed database built for modern application developers and for the cloud era.
Wikipedia defines MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with an optional schema. MongoDB is developed by MongoDB Inc.
From the above two definitions, let's see the key pointers that define MongoDB:
Document database
Cross-platform
Scalable
Flexible
Classified as a NoSQL database
Now, let's dive a little deeper into these concepts and see how these separate MongoDB from other database engines available.
What is a document database?
The document database is a type of non-relational database that is designed to store documents in JSON-like format.
What is JSON? How does it look?
JSON Stands for JavaScript Object Notation and it is one of the widely used open standard file formats which uses human-readable text to store and transmit data. It is a lightweight format for data transportation and is often used between the client and server architecture in software development.
JSON is very easy to understand and usually, it is self-describing
.
Simple JSON example:
#Example 1.1
{
Students
:[
{firstName
:Siya
, lastName
:Sharma
, Location
:India
},
{firstName
:Ron
, lastName
:Smith
, Location
:USA
},
{firstName
:Bash
, lastName
:Tao
,Location
:Philippines
}
],
Teachers
:[
{firstName
:Dheeraj
, lastName
:Sareen
, Location
:India
},
{firstName
:David
, lastName
:Baker
, Location
:Canada
}
]
}
In the preceding example:
JSON data is specified in the name and value pairs
Each data is separated by commas in JSON
The square brackets in JSON are used to hold an array of object(s)
The curly braces in JSON are used to hold object(s)
It is highly flexible and easy to understand as you write JSON in a human-understandable format.
The document-based databases make the lives of developers easier as they allow them to store data in the same document-model format as developers use JSON while coding. It is easy for them to relate the name and value pairs while referring to the data entered in these databases.
Cross-platform
MongoDB is a cross-platform database, which means it can run on various operating systems and on various computer architectures. You can run MongoDB on Windows, Linux, and even Mac Operating Systems. It also supports various computer architectures that are machine-based and hardware-specific and depends on the processors and hardware plus operating systems that run that machine.
Officially MongoDB Inc. recommends these platforms for production use (as of now):
Amazon Linux 2
Debian 9 and 10
RHEL/CentOS 6, 7, and 8
SLES 12 and 15
Ubuntu LTS 16.04 and 18.04
Windows Server 2016 and 2019
We can see that there are a number of platforms supported by MongoDB for the production use. This also means that we can install and run MongoDB on a variety of platforms like Windows, Linux, etc., and their variants.
The 32-bit MongoDB processes are limited to about 2 GB of data. So if you have large data then please consider using 64-Bit architecture.
Note that 32 Bit processes are related to the 32-bit computer architecture, these kinds of architecture are present in the old processors. New Processors are capable of handling 64-bits of data per clock cycle.
You can refer to the official MongoDB documentation here for the latest updates: https://docs.mongodb.com/manual/administration/production-notes/
Scalable
MongoDB is extremely scalable, suppose you are developing an application that is presently not widely used and has limited usage but you believe that in the coming years, your application will have a huge increase in new users and there will be a multi-fold increase in the traffic. So the choice you make now for selecting a MongoDB database for your application is worth it. MongoDB is the first choice of Fortune 100 enterprises as well as startups. These organizations rely on MongoDB for their operations. The industry has seen a dramatic increase in the deployments of MongoDB, ranging from a single server to multi servers and clusters of MongoDB database.
MongoDB offers scalability for three different metrics:
In terms of cluster
In terms of performance
Scalability in terms of data
We will cover all these topics related to Scalability in the coming chapters.
Flexible
MongoDB doesn't heavily enforce schema but uses dynamic schema, and hence, is also referred to as a schema-less database. This makes it a highly flexible database.
So first just a quick look at what is schema.
Schema is the database structure in Relational Database Management System (RDBMS) where you define it before using the database in the application. This means that you are creating a blueprint of your application data structure and defining the tables, fields, and relationships.
The advantages of using schema-less databases are as follows:
So this gives MongoDB an edge over the schema-related databases where we first define the schema and then add records or data. The problem with the schema-related databases is that each time we need to add one extra field, we have to update our schema as we cannot add a new record without adding an extra field.
MongoDB is flexible in terms of its data structure. As we have discussed earlier that MongoDB relies on the JSON-like data structure which is very flexible in itself. So when we need to add any new data in MongoDB which has or more fields and where each data is dynamic, we can easily add these records to our database in MongoDB without any issues as it won't restrict us and we are not bound to a specific data structure to be added in the database.
Many organizations throughout the world rely on MongoDB because it enables their development teams to build applications faster using different data types and also allows them to manage their applications more effectively and with high flexibility.
Classified as NoSQL database
We have already seen that MongoDB is a schema-less (or a dynamic schema-based) database. Let us now learn why it is called a NoSQL database.
But before that, let us understand what the term NoSQL is and what are NoSQL databases.
What is a NoSQL database?
The NoSQL databases, sometimes also called non-SQL, non-relational, or not only SQL databases are those that have a different mechanism to store and retrieve data other than the tabular relations which are used in relational databases. These types of databases have existed long ago but the term NoSQL is new, coined because of the requirements of today's companies that work on big, real-time data, and AI applications.
There are many kinds of NoSQL databases that we will cover in the next topic.
As we know, MongoDB uses JSON-like data structures that are different from what we use in RDBMS, so it is also called a NoSQL database. We will cover other NoSQL concepts later in this chapter.
An overview of the MongoDB architecture
We will now look into how the MongoDB architecture looks like. It would be easier if we explain this with the help of some diagrams. Below is a diagram of the NoSQL database. As MongoDB is also a type of NoSQL database it would be better if we cover this first.
A quick look into the NoSQL database architecture
Figure 1.1: NoSQL database architecture
The important feature of NoSQL databases with respect to their architecture is that it provides nested, hierarchical structures in data entities. These hierarchical data structures can be easily described with the JSON and other formats used by the NoSQL databases. These structures also closely match with the data structures used in the programming languages.
A quick look into the MongoDB architecture
Now, we will cover the MongoDB architecture with the help of a diagram. If you see the diagram below, you will easily get a quick idea of how the MongoDB architecture looks like:
Figure 1.2: MongoDB architecture
In the preceding diagram, you will see that the client-side application communicates with the MongoDB database with the help of MongoDB drivers. For any read and write operations, the MongoDB drivers play an important role to communicate with the MongoDB database. The MongoDB drivers depend on the programming language and help applications for various CRUD (Create, Read, Update, and Delete) and other operations with respect to the MongoDB database. The primary and secondary DBs ensure the high availability of data and the frequent synchronization provides eventually consistent data records.
MongoDB data platform
Let us have a quick look into the MongoDB database platform. As you can see in the following figure, the MongoDB database platform gives a lot of advantages as discussed in the following section:
Figure 1.3: MongoDB Database Platform
So, MongoDB provides:
Best way: MongoDB provides an easy, fast, and flexible way to work with data. It also provides a wide range of data types and expressive queries that are easy to understand.
Best availability: MongoDB provides the best way for data availability. With MongoDB, you can place and scale your data on any device as well as at any geographic location whenever you need