-
-
Notifications
You must be signed in to change notification settings - Fork 155
MongoDB docs 21 to 25 added #935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ajay-dhangar
merged 2 commits into
codeharborhub:main
from
Vipullakum007:mongo-docs-21-to-25
Jun 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
id: mongodb-create-backup | ||
title: MongoDB - Create Backup | ||
sidebar_label: Create Backup | ||
sidebar_position: 22 | ||
tags: [mongodb, backup, database, mongodump, mongorestore] | ||
description: Learn how to create and restore backups in MongoDB using the mongodump and mongorestore commands. | ||
--- | ||
|
||
# MongoDB - Create Backup | ||
|
||
In this chapter, we will see how to create a backup in MongoDB. | ||
|
||
## Dump MongoDB Data | ||
|
||
To create a backup of a database in MongoDB, use the `mongodump` command. This command dumps the entire data of your server into the dump directory. There are many options available to limit the amount of data or create a backup of your remote server. | ||
|
||
### Syntax | ||
|
||
The basic syntax of the `mongodump` command is as follows: | ||
|
||
``` | ||
mongodump | ||
``` | ||
|
||
### Example | ||
|
||
Start your `mongod` server. Assuming that your `mongod` server is running on `localhost` and port `27017`, open a command prompt, go to the `bin` directory of your MongoDB instance, and type the command `mongodump`. | ||
|
||
Consider the `mycol` collection has the following data. | ||
|
||
``` | ||
mongodump | ||
``` | ||
|
||
The command will connect to the server running at `127.0.0.1` and port `27017` and back up all data of the server to the directory `/bin/dump/`. Following is the output of the command: | ||
|
||
```plaintext | ||
2023-06-10T12:34:56.789+0000 writing mydb.mycol to /bin/dump/mydb/mycol.bson | ||
2023-06-10T12:34:56.789+0000 done | ||
``` | ||
|
||
## Available Options for `mongodump` | ||
|
||
| Syntax | Description | Example | | ||
|---------------------------------------------|----------------------------------------------------------|---------------------------------------------------------| | ||
| `mongodump --host HOST_NAME --port PORT_NUMBER` | This command will back up all databases of the specified `mongod` instance. | `mongodump --host tutorialspoint.com --port 27017` | | ||
| `mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY` | This command will back up only the specified database at the specified path. | `mongodump --dbpath /data/db/ --out /data/backup/` | | ||
| `mongodump --collection COLLECTION --db DB_NAME` | This command will back up only the specified collection of the specified database. | `mongodump --collection mycol --db test` | | ||
|
||
## Restore Data | ||
|
||
To restore backup data, use MongoDB's `mongorestore` command. This command restores all of the data from the backup directory. | ||
|
||
### Syntax | ||
|
||
The basic syntax of the `mongorestore` command is: | ||
|
||
``` | ||
mongorestore | ||
``` | ||
|
||
### Example | ||
|
||
Following is the output of the command: | ||
|
||
```plaintext | ||
2023-06-10T12:34:56.789+0000 preparing to restore mydb.mycol from /bin/dump/mydb/mycol.bson | ||
2023-06-10T12:34:56.789+0000 done | ||
``` | ||
|
||
### Diagram | ||
|
||
```mermaid | ||
graph TD; | ||
A[Client Application] --> B[Mongod Server] | ||
B --> C{mongodump} | ||
C --> D[Backup Directory] | ||
E[Backup Directory] --> F{mongorestore} | ||
F --> B | ||
``` | ||
|
||
### Notes | ||
> - Ensure the `mongod` server is running before executing the `mongodump` or `mongorestore` commands. | ||
> - Use appropriate options with `mongodump` to back up specific databases or collections. | ||
> - The backup directory should be accessible and writable by the MongoDB instance. | ||
|
||
Creating backups regularly ensures that you have a recovery option in case of data loss or corruption. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
--- | ||
id: mongodb-deployment | ||
title: MongoDB - Deployment | ||
sidebar_label: Deployment | ||
sidebar_position: 23 | ||
tags: [mongodb, deployment, monitoring, mongostat, mongotop] | ||
description: Learn how to deploy and monitor MongoDB in a production environment. | ||
--- | ||
|
||
# MongoDB - Deployment | ||
|
||
When you are preparing a MongoDB deployment, you should try to understand how your application is going to hold up in production. It’s a good idea to develop a consistent, repeatable approach to managing your deployment environment so that you can minimize any surprises once you’re in production. | ||
|
||
The best approach incorporates prototyping your setup, conducting load testing, monitoring key metrics, and using that information to scale your setup. The key part of the approach is to proactively monitor your entire system - this will help you understand how your production system will hold up before deploying and determine where you will need to add capacity. Having insight into potential spikes in your memory usage, for example, could help put out a write-lock fire before it starts. | ||
|
||
## Monitoring Your Deployment | ||
|
||
To monitor your deployment, MongoDB provides some of the following commands: | ||
|
||
### `mongostat` | ||
|
||
This command checks the status of all running `mongod` instances and returns counters of database operations. These counters include inserts, queries, updates, deletes, and cursors. The command also shows when you’re hitting page faults and showcases your lock percentage. This means that you're running low on memory, hitting write capacity, or have some performance issues. | ||
|
||
To run the command, start your `mongod` instance. In another command prompt, go to the `bin` directory of your MongoDB installation and type `mongostat`. | ||
|
||
```shell | ||
D:\set up\mongodb\bin>mongostat | ||
``` | ||
|
||
Following is the output of the command: | ||
|
||
```plaintext | ||
insert query update delete getmore command % dirty % used flushes vsize res qrw arw net_in net_out conn time | ||
*0 *0 *0 *0 0 1|0 0 0 0 54.3M 2.0M 0|0 0|0 0 0 1 2024-06-10T12:34:56.789+0000 | ||
``` | ||
|
||
### `mongotop` | ||
|
||
This command tracks and reports the read and write activity of MongoDB instances on a collection basis. By default, `mongotop` returns information each second, which you can change accordingly. You should check that this read and write activity matches your application intention, and you’re not firing too many writes to the database at a time, reading too frequently from a disk, or exceeding your working set size. | ||
|
||
To run the command, start your `mongod` instance. In another command prompt, go to the `bin` directory of your MongoDB installation and type `mongotop`. | ||
|
||
```shell | ||
D:\set up\mongodb\bin>mongotop | ||
``` | ||
|
||
Following is the output of the command: | ||
|
||
```plaintext | ||
ns total read write 2024-06-10T12:34:56.789+0000 | ||
mydb.mycol 0ms 0ms 0ms | ||
``` | ||
|
||
To change the `mongotop` command to return information less frequently, specify a specific number after the `mongotop` command. | ||
|
||
```shell | ||
D:\set up\mongodb\bin>mongotop 30 | ||
``` | ||
|
||
The above example will return values every 30 seconds. | ||
|
||
## MongoDB Management Service (MMS) | ||
|
||
Apart from the MongoDB tools, 10gen provides a free, hosted monitoring service, MongoDB Management Service (MMS), that provides a dashboard and gives you a view of the metrics from your entire cluster. | ||
|
||
## Diagram | ||
|
||
```mermaid | ||
graph TD; | ||
A[Prepare Deployment] --> B[Prototype Setup] | ||
B --> C[Load Testing] | ||
C --> D[Monitor Key Metrics] | ||
D --> E[Scale Setup] | ||
E --> F[Deploy in Production] | ||
F --> G[Monitor Deployment] | ||
G --> H{Monitoring Tools} | ||
H --> I[mongostat] | ||
H --> J[mongotop] | ||
H --> K[MMS] | ||
``` | ||
|
||
### Notes | ||
ajay-dhangar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
> - Regularly prototype, test, and monitor your deployment environment. | ||
> - Use `mongostat` to check the status of your `mongod` instances and monitor database operations. | ||
> - Use `mongotop` to track and report read/write activity on a collection basis. | ||
> - Utilize MongoDB Management Service (MMS) for comprehensive monitoring and a visual dashboard. | ||
|
||
Having a well-planned and monitored deployment strategy ensures the stability and performance of your MongoDB in a production environment. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basic Practice
Good Practice