Two separate database seeding scripts have been successfully created and tested for your ecommerce application.
- scripts/seed-deals.js - Loads 10 special deal products
- scripts/SEEDING_GUIDE.md - Comprehensive seeding documentation
- scripts/seed-products.js - Enhanced with better formatting and error handling
- package.json - Added npm scripts for easy execution
- ✅ Loads 12 regular products across 4 categories
- ✅ Products marked with
isDeal: falsefor filtering - ✅ Enhanced error handling and formatted output
- ✅ Automatically clears existing products (not deals)
- ✅ Beautiful terminal output with product summary
- ✅ Loads 10 special deal products with 56-67% discounts
- ✅ Products marked with
isDeal: truefor filtering - ✅ Includes
dealEndDatefor deal expiration tracking - ✅ Products automatically marked with discount percentage
- ✅ Automatically clears existing deals (not products)
- ✅ Same error handling and formatted output as products script
# Seed only products
npm run seed:products
# Seed only deals
npm run seed:deals
# Seed everything (products + deals)
npm run seed:all
# Legacy command (same as seed:products)
npm run seed- Electronics: 5 items
- Fashion: 3 items
- Sports: 2 items
- Home & Kitchen: 2 items
- Discount Range: 56% - 67% OFF
- Deal Expiration: 2-10 days from now
- High-value items: $49.99 - $699.99
Both scripts have been successfully run against your MongoDB Atlas cluster:
✅ Products Script: 12 products loaded ✅ Deals Script: 10 deals loaded ✅ Total Items: 22 products in database
- Uses
MONGO_URIfrom.env.local - Uses
DB_NAMEfrom.env.local - Connection timeout: 10 seconds
- Server selection timeout: 5 seconds
{
id: Number (unique identifier),
name: String,
price: Number (sale price),
originalPrice: Number,
rating: Number (0-5),
reviews: Number,
image: String (Unsplash URL),
category: String,
badge: String (optional),
description: String,
stock: Number,
isDeal: Boolean (true for deals, false for regular products),
dealEndDate: Date (only for deals)
}- Products and deals are stored in the same collection
- Separated by
isDealfield for easy filtering - Clearing products only clears
isDeal: false - Clearing deals only clears
isDeal: true
Ensure .env.local contains:
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/databasename
DB_NAME=ecommerce# First time setup - load everything
npm run seed:all
# Verify both types loaded correctly
npm run dev # Start your app and check /products and /deals pagesnpm run seed:productsnpm run seed:deals- Edit
scripts/seed-products.js - Add to the
productsarray - Run
npm run seed:products
- Easy Execution: Simple npm commands instead of manual MongoDB inserts
- Repeatable: Run anytime to reset data
- Well-Documented: Comprehensive seeding guide included
- Error Handling: Clear error messages if something fails
- Data Isolation: Products and deals kept separate for filtering
- Beautiful Output: Formatted console output with emojis and summary
- Fast Setup: Load 22 sample products in seconds
The seeded data works with:
/api/products- Returns all products whereisDeal: false/api/deals- Returns all products whereisDeal: true- Product filtering by category, price range, ratings
- Shopping cart (can use any seeded product)
- Order creation (uses seeded products)
Comprehensive seeding guide available at:
website/scripts/SEEDING_GUIDE.md
Includes:
- Setup instructions
- Troubleshooting tips
- Data customization guide
- FAQ section
- Database schema reference
- ✅ Scripts created and tested
- ✅ Data loaded to MongoDB
- 📋 Optional: Customize data by editing scripts
- 🚀 Ready for development!
Status: ✅ Complete and Tested Last Updated: January 16, 2026 Database: MongoDB Atlas Total Records Seeded: 22 products