Skip to content

Instantly share code, notes, and snippets.

@dungmanh88
Last active January 22, 2024 07:42
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dungmanh88/d44b0c9938bc5d6a752f2f5051b0787d to your computer and use it in GitHub Desktop.
Save dungmanh88/d44b0c9938bc5d6a752f2f5051b0787d to your computer and use it in GitHub Desktop.
Dump multiple collections of a db in mongodb
#!/bin/bash
db=<db>
collection_list="<collection1> <collection2> <collection3>"
host=127.0.0.1
port=<port>
out_prefix=/Temp
for collection in $collection_list; do
echo $collection
out_dir="${out_prefix}/${db}_${collection}/"
mkdir -p ${out_dir}
mongodump --host $host --port $port --collection $collection --db $db --out ${out_dir}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment