-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.js
More file actions
33 lines (27 loc) · 931 Bytes
/
Copy pathseed.js
File metadata and controls
33 lines (27 loc) · 931 Bytes
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
31
32
33
const mongoose = require("mongoose");
const Product = require("./models/Product");
require("dotenv").config();
const seedProduct = async () => {
try {
await mongoose.connect(process.env.MONGO_URI);
console.log("⚡ Seed script connected to MongoDB...");
await Product.deleteMany({});
console.log("🧹 Cleaned old product entries.");
const flashSaleItem = new Product({
title: "iPhone 16 Pro Limited Edition",
price: 119900,
productId: "iphone-16-pro",
initialStock: 50,
currentStock: 50,
});
await flashSaleItem.save();
console.log("📦 Flash sale item successfully injected into the database!");
await mongoose.connection.close();
console.log("🔌 Database connection cleanly closed. Seeding complete!");
process.exit(0);
} catch (error) {
console.error("❌ Seeding failed with error:", error);
process.exit(1);
}
};
seedProduct();