Skip to content

Instantly share code, notes, and snippets.

@matlads
Created August 2, 2016 08:43
Show Gist options
  • Save matlads/a879fd92c48238a32373e15089427294 to your computer and use it in GitHub Desktop.
Save matlads/a879fd92c48238a32373e15089427294 to your computer and use it in GitHub Desktop.
Bash script to output a set of mongo collections to files ( as csv )
#!/bin/bash
collections=('account', 'admin', 'alarm')
MONGO_PORT=27117
MONGO_FIELDS='_id,attr_hidden,attr_hidden_id,attr_no_delete,attr_no_edit,name,site_id'
for collection in ${collections[*]}; do
# echo the command
echo mongoexport --port $MONGO_PORT -d ace -c $collection -f $MONGO_FIELDS --csv -o $collection.csv
# now actually execute it
mongoexport --port $MONGO_PORT -d ace -c $collection -f $MONGO_FIELDS --csv -o $collection.csv
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment