Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Created March 7, 2016 03:07
Show Gist options
  • Save githubutilities/44b16e0ade7450d5689d to your computer and use it in GitHub Desktop.
Save githubutilities/44b16e0ade7450d5689d to your computer and use it in GitHub Desktop.
Mongo cheatsheet
# Export to json
mongoexport -d <database> -c <collection> -o <out-file>
# Export to csv
mongoexport --csv -o <out-file> -d <database> -c <collection> -f <field-1>, <field-2>
# Import from json
mongoimport -d <database> -c <collection> <in-file>
# Import from csv
mongoimport -d <database> -c <collection> --type csv --file <in-file>
# Import from csv with headerline
mongoimport -d <database> -c <collection> --type csv --file <in-file> --headerline
# Dump database
mongodump -d <database> -o <out-directory>
# Restore database
mongorestore -d <database> <path-to-in-directory>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment