20 lines
643 B
JavaScript
20 lines
643 B
JavaScript
require('dotenv').config();
|
|
const mongoose = require('mongoose');
|
|
const Product = require('../models/Product');
|
|
|
|
const seedProducts = [
|
|
{ name: 'iPhone 14', category: 'Electronics', price: 999 },
|
|
{ name: 'Nike Air Max', category: 'Footwear', price: 120 },
|
|
{ name: 'Sony Headphones', category: 'Electronics', price: 199 }
|
|
];
|
|
|
|
mongoose.connect(process.env.MONGODB_URI)
|
|
.then(async () => {
|
|
console.log('MongoDB connected');
|
|
await Product.deleteMany(); // Optional: clears old data
|
|
await Product.insertMany(seedProducts);
|
|
console.log('Sample products inserted');
|
|
process.exit();
|
|
})
|
|
.catch(err => console.log(err));
|