Skip to content

Instantly share code, notes, and snippets.

@thbkrkr
Created April 16, 2015 21:17
Show Gist options
  • Save thbkrkr/7617edf1f540a04f482a to your computer and use it in GitHub Desktop.
Save thbkrkr/7617edf1f540a04f482a to your computer and use it in GitHub Desktop.
Export all MongoDB collections to JSON
#!/bin/bash
DB=$1
COLLECTIONS=$(mongo localhost:27017/$DB --quiet --eval "db.getCollectionNames()" | sed 's/,/ /g')
for collection in $COLLECTIONS; do
echo "Exporting $DB/$collection ..."
mongoexport -d newtickettoolDB -c $collection -o $collection.json
done
@enioha
Copy link

enioha commented Oct 17, 2018

mongo localhost:27017/integradornfse --quiet --eval "db.getCollectionNames()"| sed 's/,/\n/g'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment