Last active
December 24, 2015 16:39
-
-
Save dnprock/6829661 to your computer and use it in GitHub Desktop.
Export meteor mongodb users to CSV format. Useful for email marketing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// # 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