forked from EricFithian/725-mern
-
Notifications
You must be signed in to change notification settings - Fork 1
/
seed.js
30 lines (25 loc) · 936 Bytes
/
seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require("dotenv").config();
const { MONGODB_URI } = process.env;
const axios = require('axios');
// Add in mongoose
const mongoose = require('mongoose');
mongoose.connect(MONGODB_URI);
// Connection Events
mongoose.connection
.on("open", () => console.log("This is my awesome amazing connection man"))
.on("close", () => console.log("Your are disconnected from mongoose :'("))
.on("error", (error) => console.log(error));
const { Breweries } = require('./models')
const seedingData = async () => {
try {
const myBreweries = await axios.get('https://api.openbrewerydb.org/breweries');
const allBreweries = myBreweries.data;
const deletedBreweries = await Breweries.deleteMany({});
const addedBreweries = await Breweries.insertMany(allBreweries);
console.log(deletedBreweries);
console.log(addedBreweries);
} catch(err) {
console.log(err);
}
}
seedingData();