6.0 KiB
Database Seeding Guide
🌱 Quick Start
To populate your database with sample marketplace items:
# Make sure MongoDB is running
mongod
# In another terminal, navigate to project root
cd TurboTrades
# Run the seed script
npm run seed
That's it! Your database is now populated with sample items.
📊 What Gets Seeded
Items Created
-
CS2 Items: 20+ skins including:
- Legendary rifles (AK-47 | Redline, M4A4 | Howl, AWP | Dragon Lore)
- Premium pistols (Desert Eagle | Blaze, Glock-18 | Fade)
- High-value knives (Karambit | Fade, Butterfly Knife | Doppler)
- Exclusive gloves (Sport Gloves | Pandora's Box)
- Various rarities and price points ($12.99 - $8,999.99)
-
Rust Items: 4+ skins including:
- AK-47 | Glory
- Python Revolver | Tempered
- MP5 | Tempered
- Metal Facemask | Red Hazmat
Default Admin User
If no admin user exists, one will be created:
- Username: TurboTrades Admin
- Steam ID: 76561198000000000
- Staff Level: 3 (Admin)
- Balance: $100,000
- Trade URL: Pre-configured
All items are listed by this admin user.
🎯 After Seeding
1. Start the Backend
npm run dev
2. Start the Frontend
cd frontend
npm run dev
3. View Items in Browser
Open http://localhost:5173 and you should see:
- Featured items on homepage
- Full marketplace at
/market - Items with images, prices, and details
- Working filters and search
🔍 Verify Seeding
Check MongoDB Directly
# Connect to MongoDB
mongosh
# Use the database
use turbotrades
# Count items
db.items.countDocuments()
# Should return 24+
# View a sample item
db.items.findOne()
# Check featured items
db.items.find({ featured: true }).count()
# Should return 8
# Check by game
db.items.find({ game: 'cs2' }).count()
db.items.find({ game: 'rust' }).count()
Check via API
# Get all items
curl http://localhost:3000/market/items
# Get featured items
curl http://localhost:3000/market/featured
# Get market stats
curl http://localhost:3000/market/stats
🗑️ Clear Database
To remove all seeded items and start fresh:
Option 1: Re-run Seed Script
The seed script automatically clears existing items before inserting new ones:
npm run seed
Option 2: Manual Clear (MongoDB)
mongosh
use turbotrades
# Delete all items
db.items.deleteMany({})
# Verify
db.items.countDocuments()
Option 3: Drop Entire Database
mongosh
use turbotrades
# Drop the entire database
db.dropDatabase()
# Then re-seed
exit
npm run seed
🎨 Customize Seed Data
Edit seed.js to customize the items:
Add More Items
// In seed.js, add to cs2Items or rustItems array:
{
name: 'Your Item Name',
description: 'Item description',
image: 'https://your-image-url.com/image.jpg',
game: 'cs2', // or 'rust'
category: 'rifles', // rifles, pistols, knives, gloves, etc.
rarity: 'legendary', // common, uncommon, rare, mythical, legendary, ancient, exceedingly
wear: 'fn', // fn, mw, ft, ww, bs (or null for Rust items)
float: 0.01, // 0-1 for CS2, null for Rust
statTrak: false,
price: 99.99,
featured: false,
}
Change Featured Items
Set featured: true on items you want to appear on the homepage.
Adjust Prices
Modify the price field for any item.
🐛 Troubleshooting
Error: Cannot connect to MongoDB
❌ Error: connect ECONNREFUSED 127.0.0.1:27017
Solution: Start MongoDB first
mongod
Error: No admin user created
Solution: The script creates one automatically. If issues persist:
mongosh
use turbotrades
db.users.findOne({ staffLevel: { $gte: 3 } })
Items not showing in frontend
- Check backend is running:
http://localhost:3000/health - Check API returns items:
http://localhost:3000/market/items - Check browser console for errors
- Verify MongoDB has data:
db.items.countDocuments()
Images not loading
The seed script uses placeholder Steam CDN URLs. Some may not work. You can:
- Update image URLs in
seed.js - Use your own hosted images
- Replace with placeholder services like
https://via.placeholder.com/330x192
📝 Seed Script Details
What It Does
- Connects to MongoDB
- Clears existing items (
Item.deleteMany({})) - Finds or creates an admin user
- Inserts all items with random listing dates
- Displays summary statistics
- Disconnects from MongoDB
Safe to Run Multiple Times
Yes! The script clears old data first, so you can run it anytime to refresh your data.
Script Location
- File:
TurboTrades/seed.js - Model:
TurboTrades/models/Item.js - Command:
npm run seed
🚀 Production Considerations
DO NOT Use Seed Data in Production
This seed data is for development and testing only.
For production:
- Remove seed script or restrict access
- Implement proper item creation via admin interface
- Use real Steam inventory integration
- Add proper image hosting/CDN
- Implement trade bot integration
Backup Before Seeding
If you have real data:
# Backup
mongodump --db turbotrades --out ./backup
# Restore if needed
mongorestore --db turbotrades ./backup/turbotrades
✅ Success Checklist
After seeding, verify:
- Seed script completed without errors
- MongoDB contains 24+ items
- Admin user exists in database
- Backend starts successfully
/market/itemsAPI endpoint returns data- Frontend displays items on homepage
- Featured items show on homepage
- Market page shows full item list
- Filters work (game, category, rarity)
- Search works (try "AK-47" or "Dragon")
- Item details page loads
🎉 You're All Set!
Your marketplace now has sample data and is ready to use!
Next Steps:
- Explore the marketplace in your browser
- Test purchasing (requires Steam login)
- Try different filters and search
- Check item detail pages
- Start building new features!
Created: January 2025 Version: 1.0.0 Seed Data: 24+ items, 1 admin user