Export a mongo collection as csv

Started to create a script to do this, then realised mongoexport can do this out of the box!

# Note the field names required cannot have any spaces between them

# Note -q is optional. note any $ need escaping, plus other shell sensitive characters

mongoexport --host localhost --db --collection -f name,app_contact_name,app_contact_email -q <json query> --csv > test.csv

Tags: mongodb