Created
October 17, 2016 11:49
-
-
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`
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
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