Skip to content

Commit f16689a

Browse files
authored
Merge pull request #14 from weaponsforge/feature/weaponsforge-13
Feature/weaponsforge 13
2 parents 6874c06 + a1ddd99 commit f16689a

File tree

4 files changed

+552
-496
lines changed

4 files changed

+552
-496
lines changed

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
localhost
2+
test
3+
27017
4+
tester
5+
tester
6+
mongosh

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.tempfile
2+
.env
23
.dbs
34
*/

README.md

Lines changed: 65 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,49 @@
1313
1. **Windows 10 OS 64-bit**
1414

1515
2. **MongoDB**
16-
Version is not strict but for references, **MongoDB Community Server v4.2.0, OS Windows x86 x64** was used for this project's local installation.
16+
Version is not strict, but for reference, the project used **MongoDB Community Server v4.2.0, OS Windows x86 x64** for its INITIAL local installation in 2019. Its shell must be available globally from the command line.
1717

1818
MongoDB shell version v4.2.0
1919
git version: a4b751dcf51dd249c5865812b390cfd1c0129c30
2020
allocator: tcmalloc
2121
modules: none
2222
build environment:
23-
distmod: 2012plus
24-
distarch: x86_64
25-
target_arch: x86_64
23+
distmod: 2012plus
24+
distarch: x86_64
25+
target_arch: x86_64
2626

27+
The project used **MongoDB Community Server v7.0.3, OS Windows x86 x64**, available on [the link](https://www.mongodb.com/try/download/community) for its LATEST local installation in 2023. This MongoDB version requires a separate installation of the MongoDB Shell and the MongoDB Database Tools (mongodump, mongorestore, etc). Its shell and tools must be available globally from the command line.
2728

28-
3. Access to an [mlab](https://mlab.com/) database (or any other mongodb database sources).
29+
MongoDB (mongod) version v7.0.3
30+
git version: b96efb7e0cf6134d5938de8a94c37cec3f22cff4
31+
allocator: tcmalloc
32+
modules: none
33+
build environment:
34+
distmod: windows
35+
distarch: x86_64
36+
target_arch: x86_64
37+
38+
**MongoDB Shell** [[link]](https://www.mongodb.com/try/download/shell)
39+
40+
MongoDB Shell v2.0.2
41+
Platform: Windows x64 (10+)
42+
Package: msi
2943

30-
host: localhost
31-
port: 27017
44+
**MongoDB Command Line Database Tools** (MongoDB Database Tools) [[link]](https://www.mongodb.com/try/download/database-tools)
45+
46+
MongoDB Database Tools v100.9.3
47+
Platform: Windows x86_64
48+
Package: msi
49+
50+
3. Access to an [Atlas](https://www.mongodb.com/atlas) database (or any other mongodb database sources).
51+
52+
host: localhost
53+
port: 27017
3254
user: tester
3355
password: tester
34-
56+
mongo shell:
57+
- mongo (for MongoDB v4.2.0 or lower versions)
58+
- mongosh (for MongoDB v4.4.0 or higher versions)
3559

3660

3761
## Content
@@ -40,52 +64,50 @@ Version is not strict but for references, **MongoDB Community Server v4.2.0, OS
4064
Windows batch script to automate switching of MongoDB database credentials for a faster database export `(mongodump)`, import `(mongorestore)` and database drop process.
4165

4266

43-
4467
## Usage
4568

4669
1. Clone this repository.
4770
`git clone https://github.com/weaponsforge/mongo-importex.git`
4871

4972
2. Click to run **main.bat**.
5073

51-
3. The **MONGODB CONNECTION CREDENTIALS SETUP** screen will appear on the script's first-time run. Select the following options to encode the following required fields:
52-
- **[1]** - database host name
53-
- **[2]** - database name
54-
- **[3]** - database user
55-
- **[4]** - database user's password
56-
57-
4. Press **[6] - Save** to save the previously encoded database credentials for future use and exit to the main screen.
58-
59-
5. Press **[7] Save and Export Database** to save the previously encoded database credentials and start database export `(mongodump)`.
60-
61-
6. If you already have exported binary databases directories saved in this project's root directory, press **[8] - Save and Import Database** to save the previously encoded database credentials, and to start the database import `(mongorestore)` of the binary database which you will get to select on the resulting **AVAILABLE DATABASES TO IMPORT** screen.
62-
63-
64-
7. Press **[9] Export Database** to start the database export process using the credentials that have been previously encoded.
65-
> **NOTE:** Any updates made to the database credentials will NOT be saved if this option is chosen.
66-
67-
8. Press **[10] Import Database** to select a binary database to import from the **AVAILABLE DATABASES TO IMPORT** screen. A list of exported binary database directories will be listed.
68-
> **NOTE:** Any updates made to the database credentials will NOT be saved if this option is chosen.
69-
- Enter the name of the database you want to import, or
70-
- Press **"x"** to exit.
71-
72-
9. Wait for the database export `(mongodump)` or import `(mongorestore)` process to finish.
73-
74-
10. Quick links for database import, export, drop and database credentials updating are available in the **VIEWING THE [ACTIVE] MONGODB CONNECTION CREDENTIALS** screen, which will be accessible after saving the initial database credentials required from **# 3**.
75-
- **[1] - Export Database**
76-
- **[2] - Import Database**
77-
- **[3] - Drop Database**
78-
- **[4] - Update Connection Credentials**
79-
- **[5] - Reset**
80-
- **[x] - Exit**
81-
74+
3. The **MONGODB CONNECTION CREDENTIALS SETUP** screen will appear on the script's first run. Select the following options to encode the following required fields:
75+
76+
| NO. | Prompt | Description |
77+
|---|---|---|
78+
| 1 | Enter database host | MongoDB host name |
79+
| 2 | Enter database name | MongoDB database name |
80+
| 3 | Database port | MongoDB port number name. Uses 27017 by default. |
81+
| 4 | Enter user name | MongoDB user name |
82+
| 5 | Enter password | MongoDB user password |
83+
| 6 | Enter mongo shell | The available and active MongoDB shell. Choose:<br> - `mongo` (for MongoDB v4.2.0 or lower versions) <br>- `mongosh` (for MongoDB v4.4.0 or higher versions)|
84+
| 7 | Save | Saves the encoded database credentials for future use to a `.env` and exit to the main screen. |
85+
| 8 | Save and Export Database | Saves the mongodb settings to a `.env` file and starts the Export Database process. |
86+
| 9 | Save and Import Database | Saves the mongodb settings to a `.env` file and starts to the Import Database process. |
87+
| 10 | Export Database | Exports (`mongodump`) Exports the database defined in the MongoDB Connection Credentials Setup to a database in binary JSON format.<br> - **NOTE:** Choosing this option will NOT save recent updates made to the database credentials. |
88+
| 11 | Import Database | Imports (`mongorestore`) a binary database to the database defined in the MongoDB Connection Credentials settings.<br>It expects to find binary database contents in subdirectories relative to the script, similar to the output of the **[10] Export Database option**.<br>**NOTE:** Choosing this option will NOT save recent updates made to the database credentials. |
89+
| x | Exit | Exit the script. |
90+
91+
4. The **VIEWING THE [ACTIVE] MONGODB CONNECTION CREDENTIALS** screen provides quick links for database import, export, drop, and database credentials updating, which will be accessible after saving the initial database credentials required from the **MONGODB CONNECTION CREDENTIALS SETUP**.
92+
93+
| NO. | Prompt | Description |
94+
|---|---|---|
95+
| 1 | Export Database | Exports (`mongodump`) the database defined in the MongoDB Connection Credentials Setup to a binary JSON format database. |
96+
| 2 | Import Database | Imports (`mongorestore`) the database defined in the MongoDB Connection Credentials settings to a local binary JSON format database relative to the script's location |
97+
| 3 | Drop Database | It deletes a database defined in the MongoDB connection credentials. Currently available only for localhost MongoDB. |
98+
| 4 | Update Connection Credentials | Displays the **MONGODB CONNECTION CREDENTIALS SETUP** screen for editing the stored database connection details. |
99+
| 5 | Reset | Resets the database conection details |
100+
| 6 | Exit | Exit the script. |
82101

83102

84103
## Troubleshooting
85104

86-
1. MonogoDB databases that are to be accessed using this tool are expected to have been properly set-up with users and passwords.
87-
88-
2. If the **export database** process takes too long to finish, close this tool and re-check if the database credentials haven been encoded properly.
105+
1. This script expects to access properly configured MonogoDB databases with existing users and passwords.
106+
2. The script expects a properly set up and configured MongoDB installation.
107+
- The `"mongod,"` `"mongodump,"` `"mongorestore,"` `"mongosh"` (for MongoDB v4.4 or later versions), and `"mongo"` (for MongoDB v4.2 or earlier versions) MongoDB shell commands should be globally accessible from the command prompt.
108+
2. If the **Export Database** process takes too long to finish:
109+
- Terminate and re-run the script.
110+
- Re-check if the correct database credentials are available in the **MONGODB CONNECTION CREDENTIALS SETUP** screen.
89111

90112

91113
20191116

0 commit comments

Comments
 (0)