# Mongo Dump commands
## Basic command to create a compressed dump file from a given monogodb host
```
mongodump -h hostname --port=port -d dbname --gzip --archive=path_to_archive_including_archive_file_name
```
To get the uncompressed version, exclude the --gzip flag
## If db needs credentials to access include username with -u parameter and -p for password
```
mongodump -h hostname --port=port -d dbname -u username -p "password" --gzip --archive=path_to_archive_including_archive_file_name
```
## To dump a specific collection add the --collection parameter
```
mongodump -h hostname --port=port -d dbname --collection collection_name --gzip --archive=path_to_archive_including_archive_file_name
```
## To query the collection or database before dumping add a --query parameter
The query parameter should be a JSON document. Ensure that the query parameter is enclosed in single quotes(e.g. ') for UNIX system and double quotes(e.g. ") fir Windows system
```
mongodump -h hostname --port=port -d dbname --collection collection_name -q '{query}' --gzip --archive=path_to_archive_including_archive_file_name
```