mysqldump <DATABASE_NAME> | gzip -c | ssh user@remotehost "cat > /path/to/some-file.sql.gz"
mongodump <ANY PARAMS> --out - | gzip -c | ssh user@remotehost "cat > /path/to/dump.gz"
To send the database dump to standard output, specify "-" instead of a path. Write to standard output if you want process the output before saving it, such as to use gzip to compress the dump. When writing standard output, mongodump does not write the metadata that writes in a .metadata.json file when writing to files directly.