Skip to content

Instantly share code, notes, and snippets.

@mjlescano
Created October 17, 2016 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjlescano/fe493389cd171690e16de1542d76883f to your computer and use it in GitHub Desktop.
Save mjlescano/fe493389cd171690e16de1542d76883f to your computer and use it in GitHub Desktop.
Topics with Author CSV export example - DemocracyOS | Runs with `NODE_PATH=. node tocsv.js`
var fs = require('fs')
var json2csv = require('json2csv')
var models = require('lib/models')
models()
var Topic = models.Topic
Topic
.find({deletedAt: null})
.populate('author')
.exec(function (err, data) {
if (err) throw err
json2csv({
data: data,
fields: [
'_id',
'mediaTitle',
'author._id',
'author.fullName',
]
}, function (err, csv) {
if (err) throw err
fs.writeFile('export.csv', csv, function(err) {
if (err) throw err
console.log('· done.')
process.exit(0)
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment