I'd like to specify the directory to which mongodump dumps, via a switch on the mongodump command. Is this possible?
Asked
Active
Viewed 3.4k times
4 Answers
62
You don't need a script. From the docs:
--out <path>, -o <path>
Specifies the directory where mongodump will write BSON files for the dumped databases.
Example:
mongodump -o /mydir/
Lots of other options there, check it out.

Mark Amery
- 143,130
- 81
- 406
- 459

Justin Jenkins
- 26,590
- 6
- 68
- 1,285
1
You can view all the commands for mongodump by typing "mongodump --help" in the command prompt (NB. You have to be in the folder that contains mongodump.exe).
You can use a command like:
mongodump /host <hostIP> /port <port> /d <database> /c <collection> /o <outputDirectoryPath>

JavaadPatel
- 97
- 11
1
It Dumps my_db in a gzip format inside tmp/my_db.dump file which is Restoreable
mongodump --db my_db --gzip -o ./tmp/my_db.dump

Kabeer Jaffri
- 652
- 1
- 9
- 9
-
1Please explain what this command do. So other people can benefit from your answer. Just a command as answer is not really meaningful. – SwissCodeMen Dec 04 '20 at 10:47
-
It Dumps my_db in a gzip format inside tmp/my_db.dump file – Kabeer Jaffri Dec 05 '20 at 13:45
-
which is Restoreable – Kabeer Jaffri Dec 05 '20 at 13:45
-
Please add the explanation to the answer not below in the comments. – SwissCodeMen Dec 05 '20 at 13:54
1
When I am using windows I always use the command below because it exports in a folder with export date:
setlocal enableextensions
set FOLDER_NAME=%DATE:/=_%
mongodump --uri "mongodb+srv://USER:PASSWORD@URL/DATABASE_NAME" -o C:\work\scheduled\dump\backup-%FOLDER_NAME%
Save the command in a file with bat extension (dump.bat for example)

thiagotrss
- 129
- 4