text: //required libraries
  const mongoose = require('mongoose');
  const Campground = require('../models/campground');
  const cities = require('./cities')
  const { places, descriptors } = require('./seedHelpers')
  
  //connect to mongo
  mongoose.connect('mongodb://localhost:27017/yelp-camp', {
      useNewUrlParser: true,
      useCreateIndex: true,
      useUnifiedTopology: true
  })
  
  //verify connection to database
  const db = mongoose.connection;
  db.on('error', console.error.bind(console, "connection error:"));
  db.once('open', () => {
      console.log("Database connected");
  });
  
  const sample = (array) => array[Math.floor(Math.random() * array.length)];
  
  const seedDb = async () => {
      await Campground.deleteMany({});
      for (let i = 0; i < 50; i++) {
          const random1000 = Math.floor(Math.random() * 1000);
          const price = Math.floor(Math.random() * 20) + 10;
          const camp = new Campground({
              line: i + 1,
              location: `${cities[random1000].city}, ${cities[random1000].state}`,
              title: `${sample(descriptors)} ${sample(places)}`,
              image: 'http://source.unsplash.com/collection/483251',
              description: 'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Facilis optio impedit sint pariatur non quos dolore ut similique, reprehenderit beatae modi labore voluptatum natus, voluptas soluta accusamus fugiat officiis! Aspernatur!',
              price
          })
          await camp.save();
      }
  }
  
  seedDb().then(() => {
      mongoose.connection.close();
  })