Skip to content

Instantly share code, notes, and snippets.

@myctw
Last active February 6, 2024 00:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myctw/b6aa3b80316b029c2048e63733115cc8 to your computer and use it in GitHub Desktop.
Save myctw/b6aa3b80316b029c2048e63733115cc8 to your computer and use it in GitHub Desktop.
Mongodb dump multiple collections script
#!/bin/bash
host=127.0.0.1
port=27017
authDB=admin
db=[YourDB]
user=root
pwd=[YourPassword]
collections="[Collection1] [Collection2]"
output_folder="./export/"
for collection in $collections; do
echo $collection
mongodump --host $host --port $port -u $user -p $pwd --authenticationDatabase $authDB --collection $collection --db $db --out ${output_folder}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment