Skip to content

Instantly share code, notes, and snippets.

@mjlescano
Created February 1, 2017 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mjlescano/7068b0310b6d2bed225ae16fc218d6b9 to your computer and use it in GitHub Desktop.
Save mjlescano/7068b0310b6d2bed225ae16fc218d6b9 to your computer and use it in GitHub Desktop.
Imports Topics to DemcoracyOS from a JSON file
const fs = require('fs')
const mongoose = require('mongoose')
const Batch = require('batch')
const models = require('lib/models')
const data = require('./topics.json')
const ObjectId = mongoose.Schema.ObjectId
models()
const Topic = models.Topic
batch = new Batch()
data.forEach((item) => {
batch.push((done) => {
console.log(item.mediaTitle)
Topic.create({
forum: '58175ac35ad3090003ef1d37',
mediaTitle: item.mediaTitle,
coverUrl: item.coverUrl,
publishedAt: Date.now(),
closingAt: new Date('2016-11-29T02:59:00.000Z')
}, done)
})
})
batch.end((err) => {
if (err) {
console.error(err)
process.exit(1)
}
console.log('· done.')
process.exit(0)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment