Created
January 13, 2020 19:28
-
-
Save omarciovsena/30391c1c5c1d177c545ea36115c4d804 to your computer and use it in GitHub Desktop.
bibleapi - seed - book
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
import chalk from 'chalk' | |
import dotenv from 'dotenv' | |
import mongoose from 'mongoose' | |
import Book from '../../models/book' | |
import books from './data/books' | |
dotenv.config() | |
mongoose.set('useCreateIndex', true) | |
mongoose.set('useUnifiedTopology', true) | |
mongoose.set('useNewUrlParser', true) | |
mongoose.connect(`${process.env.MONGODB_URI}`) | |
mongoose.connection.on('error', err => { | |
console.error(`%s ${err}`, chalk.red('x')) | |
}) | |
Book.deleteMany({}, async () => { | |
const promises = await books.map(async (book, index) => { | |
await Book.create( | |
{ | |
abbrev: book.abbrev, | |
author: book.author, | |
chapters: book.chapters, | |
comment: book.comment, | |
group: book.group, | |
name: book.name, | |
order: index + 1, | |
testament: book.testament | |
} | |
) | |
}) | |
Promise.all(promises).then(() => { | |
process.exit() | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment