Skip to content

Instantly share code, notes, and snippets.

@rjollet
Created March 3, 2017 06:41
Show Gist options
  • Save rjollet/1f62796ec1464e53965858dee23c24fd to your computer and use it in GitHub Desktop.
Save rjollet/1f62796ec1464e53965858dee23c24fd to your computer and use it in GitHub Desktop.
export tweet with text from mongo to csv
// mongo <host>/<dbname> -u <username> -p <password> export.js > out.csv
// mongo local --quiet export_text.js > tweets_text.csv
print("id\tlang\ttext");
db.sample_stream.find({}, { 'tweet.id_str': 1, 'tweet.lang': 1,'tweet.text': 1, _id: 0}).forEach(function(doc){
print(doc.tweet.id_str + "\t" + doc.tweet.lang + "\t" + doc.tweet.text.replace(/\t|\n|\r/g, ' '));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment