Concept of Sharding process and How to create a backup in MongoDB

Last updated on May 30 2022
Satyen Sahu

Table of Contents

Concept of Sharding process and How to create a backup in MongoDB

MongoDB – Sharding

Sharding is that the process of storing data records across multiple machines and it is MongoDB’s approach to meeting the demand of data growth. As the size of the data increases, a single machine may not be sufficient to store the data nor provide an acceptable read and write throughput. Sharding solves the problem with horizontal scaling. With sharding, you add more machines to support data growth and therefore the demands of read and write operations.

Why Sharding?

• In replication, all writes attend master node
• Latency sensitive queries still attend master
• Single replica set has limitation of 12 nodes
• Memory can’t be large enough when active dataset is big
• Local disk is not big enough
• Vertical scaling is just too expensive

Sharding in MongoDB

The subsequent diagram shows the sharding in MongoDB using sharded cluster.

bigData 55
bigData

In the subsequent diagram, there are three main components −
• Shards − Shards are used to store data. They supply high availability and data consistency. In production environment, each shard may be a separate replica set.
• Config Servers − Config servers store the cluster’s metadata. This data contains a mapping of the cluster’s data set to the shards. The query router uses this metadata to focus on operations to specific shards. In production environment, sharded clusters have exactly 3 config servers.
• Query Routers − Query routers are basically mongo instances, interface with client applications and direct operations to the acceptable shard. The query router processes and targets the operations to shards then returns results to the clients. A sharded cluster can contain more than one query router to divide the client request load. A client sends requests to one query router. Generally, a sharded cluster have many query routers.

MongoDB – Create Backup

Dump MongoDB Data

To create backup of database in MongoDB, you ought to use mongodump command. This command will dump the entire data of your server into the dump directory. There are many options available by which you’ll limit the quantity of knowledge or create backup of your remote server.
Syntax
The basic syntax of mongodump command is as follows −
>mongodump
Example
Start your mongod server. Assuming that your mongod server is running on the localhost and port 27017, open a command prompt and attend the bin directory of your mongodb instance and type the command mongodump
Consider the mycol collection has the subsequent data.
>mongodump
The command will connect to the server running at 127.0.0.1 and port 27017 and back all data of the server to directory /bin/dump/. Subsequent is the output of the command −

bigData 54
bigData

Subsequent is a list of obtainable options which will be used with the mongodump command.

Syntax Description Example
mongodump –host HOST_NAME –port PORT_NUMBER This commmand will backup all databases of specified mongod instance. mongodump –host tecklearn.com –port 27017
mongodump –dbpath DB_PATH –out BACKUP_DIRECTORY This command will backup only specified database at specified path. mongodump –dbpath /data/db/ –out /data/backup/
mongodump –collection COLLECTION –db DB_NAME This command will backup only specified collection of specified database. mongodump –collection mycol –db test

Restore data

To restore backup data MongoDB’s mongorestore command is employed. This command restores all of the data from the backup directory.
Syntax
The basic syntax of mongorestore command is −
>mongorestore
Subsequent is that the output of the command −

bigData 53
bigData

So, this brings us to the end of blog. This Tecklearn ‘Concept of Sharding process and How to create a backup in MongoDB’ helps you with commonly asked questions if you are looking out for a job in MongoDB and No-SQL Database Domain.
If you wish to learn and build a career in MongoDB or No-SQL Database domain, then check out our interactive, MongoDB Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

MongoDB Training


MongoDB Training
About the Course
Tecklearn’s MongoDB Training helps you to master the NoSQL database. The course makes you job-ready by letting you comprehend schema design, data modelling, replication, and query with MongoDB through real-time examples. Along with this, you’ll also gain hands-on expertise in installing, configuring, and maintaining the MongoDB environment, including monitoring and operational strategies from this online MongoDB training. Upon completion of this online training, you will hold a solid understanding and hands-on experience with MongoDB.
Why Should you take MongoDB Training?
• MongoDB – a $36 billion to a $40 billion market growing at 8% to 9% annually – Forbes.com
• Average salary of a Mongo DB certified professional is $134k – Indeed.com
• MongoDB has more than 900 customers, including 27 Fortune 100 companies like Cisco, eBay, eHarmony, MetLife & Salesforce.com
What you will Learn in this Course?
Introduction to MongoDB and Importance of NoSQL
• Understanding the basic concepts of RDBMS
• What is NoSQL Database and its significance?
• Challenges of RDBMS and How NoSQL suits Big Data needs
• Types of NoSQL Database and NoSQL vs. SQL Comparison
• CAP Theorem and Implementing NoSQL
• Introduction to MongoDB and its advantages
• Design Goals for MongoDB Server and Database, MongoDB tools
• Collection, Documents and Key Value Pair
• Introduction to JSON and BSON documents
• MongoDB installation
MongoDB Installation
• MongoDB Installation
• Basic MongoDB commands and operations,
• Mongo Chef (MongoGUI) Installation
Schema Design and Data Modelling
• Why Data Modelling?
• Data Modelling Approach
• Data Modelling Concepts
• Difference between MongoDB and RDBMS modelling
• Challenges for Data Modelling
• Model Relationships between Documents
• Data Model Examples and Patterns
• Model Tree Structures
CRUD Operations
• MongoDB Architecture
• CRUD Introduction and MongoDB CRUD Concepts
• MongoDB CRUD Concerns (Read and Write Operations)
• Cursor Query Optimizations and Query Behaviour in MongoDB
• Distributed Read and Write Queries
• MongoDB Datatypes
Indexing and Aggregation Framework
• Concepts of Data aggregation and types and data indexing concepts
• Introduction to Aggregation
• Approach to Aggregation
• Types of Aggregation: Pipeline, MapReduce and Single Purpose
• Performance Tuning
MongoDB Administration
• Administration concepts in MongoDB
• MongoDB Administration activities: Health check, recovery, backup, database sharing and profiling, performance tuning etc.
• Backup and Recovery Methods for MongoDB
• Export and Import of Data from MongoDB
• Run time configuration of MongoDB
MongoDB Security
• Security Introduction
• MongoDB security Concepts and security approach
• MongoDB integration with Java and Robomongo
Got a question for us? Please mention it in the comments section and we will get back to you.

0 responses on "Concept of Sharding process and How to create a backup in MongoDB"

Leave a Message

Your email address will not be published. Required fields are marked *