Skip to content

Commit c0446e7

Browse files
authored
Merge pull request #935 from Vipullakum007/mongo-docs-21-to-25
MongoDB docs 21 to 25 added
2 parents f41c7a4 + 73b2030 commit c0446e7

5 files changed

+959
-0
lines changed

docs/MongoDB/mongodb-create-backup.md

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
id: mongodb-create-backup
3+
title: MongoDB - Create Backup
4+
sidebar_label: Create Backup
5+
sidebar_position: 22
6+
tags: [mongodb, backup, database, mongodump, mongorestore]
7+
description: Learn how to create and restore backups in MongoDB using the mongodump and mongorestore commands.
8+
---
9+
10+
# MongoDB - Create Backup
11+
12+
In this chapter, we will see how to create a backup in MongoDB.
13+
14+
## Dump MongoDB Data
15+
16+
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.
17+
18+
### Syntax
19+
20+
The basic syntax of the `mongodump` command is as follows:
21+
22+
```
23+
mongodump
24+
```
25+
26+
### Example
27+
28+
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`.
29+
30+
Consider the `mycol` collection has the following data.
31+
32+
```
33+
mongodump
34+
```
35+
36+
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:
37+
38+
```plaintext
39+
2023-06-10T12:34:56.789+0000 writing mydb.mycol to /bin/dump/mydb/mycol.bson
40+
2023-06-10T12:34:56.789+0000 done
41+
```
42+
43+
## Available Options for `mongodump`
44+
45+
| Syntax | Description | Example |
46+
|---------------------------------------------|----------------------------------------------------------|---------------------------------------------------------|
47+
| `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` |
48+
| `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/` |
49+
| `mongodump --collection COLLECTION --db DB_NAME` | This command will back up only the specified collection of the specified database. | `mongodump --collection mycol --db test` |
50+
51+
## Restore Data
52+
53+
To restore backup data, use MongoDB's `mongorestore` command. This command restores all of the data from the backup directory.
54+
55+
### Syntax
56+
57+
The basic syntax of the `mongorestore` command is:
58+
59+
```
60+
mongorestore
61+
```
62+
63+
### Example
64+
65+
Following is the output of the command:
66+
67+
```plaintext
68+
2023-06-10T12:34:56.789+0000 preparing to restore mydb.mycol from /bin/dump/mydb/mycol.bson
69+
2023-06-10T12:34:56.789+0000 done
70+
```
71+
72+
### Diagram
73+
74+
```mermaid
75+
graph TD;
76+
A[Client Application] --> B[Mongod Server]
77+
B --> C{mongodump}
78+
C --> D[Backup Directory]
79+
E[Backup Directory] --> F{mongorestore}
80+
F --> B
81+
```
82+
83+
:::note
84+
- Ensure the `mongod` server is running before executing the `mongodump` or `mongorestore` commands.
85+
- Use appropriate options with `mongodump` to back up specific databases or collections.
86+
- The backup directory should be accessible and writable by the MongoDB instance.
87+
:::
88+
Creating backups regularly ensures that you have a recovery option in case of data loss or corruption.

docs/MongoDB/mongodb-deployment.md

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
id: mongodb-deployment
3+
title: MongoDB - Deployment
4+
sidebar_label: Deployment
5+
sidebar_position: 23
6+
tags: [mongodb, deployment, monitoring, mongostat, mongotop]
7+
description: Learn how to deploy and monitor MongoDB in a production environment.
8+
---
9+
10+
# MongoDB - Deployment
11+
12+
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.
13+
14+
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.
15+
16+
## Monitoring Your Deployment
17+
18+
To monitor your deployment, MongoDB provides some of the following commands:
19+
20+
### `mongostat`
21+
22+
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.
23+
24+
To run the command, start your `mongod` instance. In another command prompt, go to the `bin` directory of your MongoDB installation and type `mongostat`.
25+
26+
```shell
27+
D:\set up\mongodb\bin>mongostat
28+
```
29+
30+
Following is the output of the command:
31+
32+
```plaintext
33+
insert query update delete getmore command % dirty % used flushes vsize res qrw arw net_in net_out conn time
34+
*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
35+
```
36+
37+
### `mongotop`
38+
39+
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.
40+
41+
To run the command, start your `mongod` instance. In another command prompt, go to the `bin` directory of your MongoDB installation and type `mongotop`.
42+
43+
```shell
44+
D:\set up\mongodb\bin>mongotop
45+
```
46+
47+
Following is the output of the command:
48+
49+
```plaintext
50+
ns total read write 2024-06-10T12:34:56.789+0000
51+
mydb.mycol 0ms 0ms 0ms
52+
```
53+
54+
To change the `mongotop` command to return information less frequently, specify a specific number after the `mongotop` command.
55+
56+
```shell
57+
D:\set up\mongodb\bin>mongotop 30
58+
```
59+
60+
The above example will return values every 30 seconds.
61+
62+
## MongoDB Management Service (MMS)
63+
64+
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.
65+
66+
## Diagram
67+
68+
```mermaid
69+
graph TD;
70+
A[Prepare Deployment] --> B[Prototype Setup]
71+
B --> C[Load Testing]
72+
C --> D[Monitor Key Metrics]
73+
D --> E[Scale Setup]
74+
E --> F[Deploy in Production]
75+
F --> G[Monitor Deployment]
76+
G --> H{Monitoring Tools}
77+
H --> I[mongostat]
78+
H --> J[mongotop]
79+
H --> K[MMS]
80+
```
81+
82+
:::note
83+
84+
- Regularly prototype, test, and monitor your deployment environment.
85+
- Use `mongostat` to check the status of your `mongod` instances and monitor database operations.
86+
- Use `mongotop` to track and report read/write activity on a collection basis.
87+
- Utilize MongoDB Management Service (MMS) for comprehensive monitoring and a visual dashboard.
88+
:::
89+
Having a well-planned and monitored deployment strategy ensures the stability and performance of your MongoDB in a production environment.

0 commit comments

Comments
 (0)