Skip to content

Instantly share code, notes, and snippets.

@dnprock
Last active December 24, 2015 16:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnprock/6829661 to your computer and use it in GitHub Desktop.
Save dnprock/6829661 to your computer and use it in GitHub Desktop.
Export meteor mongodb users to CSV format. Useful for email marketing.
// # get mongo temp URL
// meteor mongo --url my_app
// # dump data from mongo
// mongodump -u client -h [production_url_with_port] -d my_app -p [password_hash]
// # run your mongo server
// mongod --dbpath ./my_app_data
// # restore data
// mongorestore --db dump/my_app
// # export data to CSV
// mongo my_app extract_users.js
// modify the script if you have other social data services
var result = db.users.find({},
{emails:1,name:1,createdAt:1,'services.google.email':1,
'services.google.given_name':1,
'services.google.family_name':1}).sort({createdAt: 1})
while (result.hasNext()) {
var record = result.next()
if (record.emails) {
print(record.emails[0].address + ',' + ',' + new Date(record.createdAt))
} else if (record.services.google.email) {
print(record.services.google.email + ',' +
record.services.google.given_name + ',' +
record.services.google.family_name + ',' + new Date(record.createdAt))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment