Created
February 1, 2017 18:43
-
-
Save mjlescano/7068b0310b6d2bed225ae16fc218d6b9 to your computer and use it in GitHub Desktop.
Imports Topics to DemcoracyOS from a JSON file
This file contains hidden or 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
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