Skip to content

Instantly share code, notes, and snippets.

@montanaflynn
Last active August 29, 2015 14:07
Show Gist options
  • Save montanaflynn/42222dd1097e95367d58 to your computer and use it in GitHub Desktop.
Save montanaflynn/42222dd1097e95367d58 to your computer and use it in GitHub Desktop.
MongoDB CSV export
# mongo export all users who have an email and are not hellbanned
# take special notice that --query is in quotes and is valid JSON
# also that --fields is also wrapped with quotes and is comma seperated
mongoexport --db appname --collection users \
--query '{ "$and" : [ { "email" : { "$ne" : "" } }, { "role" : { "$ne" : 666 } } ] }' \
--csv --fields 'username, email' --out ./user-emails.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment