const mongoose = require('mongoose');
// Define MongoDB connection URI and options
const mongoURI = 'mongodb://localhost:27017/bookstore';
const mongoOptions = {
useNewUrlParser: true,
useUnifiedTopology: true,
};
// Book schema
const bookSchema = new mongoose.Schema({
title: String,
author: String,
genre: String,
publishedYear: Number
});
// Customer schema
const customerSchema = new mongoose.Schema({
name: String,
email: String,
membership: String
});
// Book model
const Book = mongoose.model('Book', bookSchema);
// Customer model
const Customer = mongoose.model('Customer', customerSchema);
// Function to seed the database
const seedDatabase = async () => {
try {
await mongoose.connect(mongoURI, mongoOptions);
console.log('Connected to MongoDB');
// Seed the database with 10 book records
const books = [
{ title: 'The Hobbit', author: 'J.R.R. Tolkien', genre: 'Fantasy', publishedYear: 1937 },
// Add more book records here
];
await Book.insertMany(books);