Create Backup in MongoDB

The mongodump command in MongoDB

To create a database Backup in MongoDB, you should use the mongodump command. This command will dump all Server data into dump directory. There are many options available from which you can limit the amount of data or backup created by Remote Server.

Syntax

The basic syntax of the mongodump command in MongoDB is:

 > mongodump 

For example

Start Mongod Server. Suppose your server is running on locallhost and port 27017. Now, open a command prompt and go to the bin directory of Mongodb Instance, then compose the mongodump command.

You monitor the Collection named mycol with the following data:

 > mongodump 

This command will connect to the running Server at 127.0.0.1 and port 27017 and backup the entire data of the Server to the / bin / dump directory . The result of this command is as follows:

Create Backup in MongoDB Picture 1

Here are some available options that can be used with the mongodump command.

Syntax Description mongodump --host HOST_NAME --port PORT_NUMBER This command will back up all databases of the mongodump --host definedspoint.com --port instance 27017 mongodump --dbpath DB_PATH - out BACKUP_DIRECTORY This command only backs up the database specified in the given path. mongodump --dbpath / data / db / --out / data / backup / mongodump --collection COLLECTION --db DB_NAME This command only backs up the specified Collection of the database with the --collection mycol --db kiểm TRA

Data recovery in MongoDB

To restore backed up data in MongoDB, use the mongorestore command. This command restores all data from the backup folder.

Syntax

The basic syntax of the mongorestore command is:

 > mongorestore 

The result of the order is:

Create Backup in MongoDB Picture 2

According to Tutorialspoint

Previous post: Shard in MongoDB

Next article: MongoDB Deployment

4 ★ | 2 Vote

May be interested

  • MongoDB DeploymentPhoto of MongoDB Deployment
    when you are preparing a mongodb deployment, you should understand how your application is being supported in production.
  • Relationship in MongoDBPhoto of Relationship in MongoDB
    relationship in mongodb represents how the documents are related. relationship can be modeled through the embeded and referenced method.
  • Reference Database in MongoDBPhoto of Reference Database in MongoDB
    as shown in the relationship chapter in mongodb, to deploy a standardized database structure in mongodb, we use the referenced relationship concept, also known as manual references, in which we manipulate to store the id of the documents referenced in another document.
  • Covered Query in MongoDBPhoto of Covered Query in MongoDB
    when all fields in the query are part of the index, mongodb connects query conditions and returns the result by using the same index without looking inside the document. when indexes are present in ram, retrieving data from indexes is faster when compared to retrieving data by scanning all documents.
  • Query analysis in MongoDBPhoto of Query analysis in MongoDB
    analyzing queries is a very important aspect to assess the effectiveness of database and the effectiveness of the designed index. we will explore the two most frequently used queries, $ explain and $ hint.
  • Atomic Operation in MongoDBPhoto of Atomic Operation in MongoDB
    mongodb does not support atomic transaction over multiple documents. however, it provides atomic operations on a single document. therefore, if a document has hundreds of fields, the update command will either update all those fields or not update any fields, thus maintaining atomicity at the document level.