Skip to main content

Overview

The SkillRise seed script (server/seed.js) populates the database with realistic demo data including:
  • 10 users (7 educators, 3 students)
  • 10 courses across various categories (Web Dev, Data Science, UI/UX, DevOps, etc.)
  • 19 purchases (students enrolled in courses)
  • 19 course progress records (tracking lecture completion)
  • 15 quizzes with multiple-choice questions
  • 4 community groups (Web Development, Data Science, UI/UX, Career)
  • 12 discussion posts with upvotes
  • 18 threaded replies
Safe to re-run: The seed script clears existing seeded data before inserting new records. Your production data remains untouched.

Prerequisites

1

Complete installation

Ensure you’ve completed Installation and Configuration.
2

Database connection

Verify MongoDB is running and MONGODB_URI is configured in server/.env.
3

Dependencies installed

cd server && npm install

Running the Seed Script

Run Seed Script Locally

1

Navigate to server directory

cd server
2

Run seed command

npm run seed
Or directly:
node seed.js
3

Verify output

You should see:
🧹 Clearing existing seed data...
👤 Seeding users...
   ✓ 10 users
📚 Seeding courses...
   ✓ 10 courses
💳 Seeding purchases...
   ✓ 19 purchases
📈 Seeding course progress...
   ✓ 19 progress records
🧠 Seeding quizzes...
   ✓ 15 quizzes
🌐 Seeding community groups...
   ✓ 4 groups
💬 Seeding posts...
   ✓ 12 posts
💬 Seeding replies...
   ✓ 18 replies
✅ Database seeded successfully!
Seeding complete! Your database now has demo data.

Seeded Data Details

Users

The seed script creates 10 users with realistic profiles:

Brad Traversy
user_seed_educator1
brad@traversymedia.com

Corey Schafer
user_seed_educator2
corey@coreyms.com

Nana Janashia
user_seed_educator3
nana@techworld-with-nana.com

Gary Simon
user_seed_educator4
gary@designcourse.com

Jeff Delaney
user_seed_educator5
jeff@fireship.io

Gaurav Sen
user_seed_educator6
gaurav@gauravsen.com

Chuck Keith
user_seed_educator7
chuck@networkchuck.com
server/seed.js:21-70
{
  _id: 'user_seed_educator1',
  name: 'Brad Traversy',
  email: 'brad@traversymedia.com',
  imageUrl: 'https://api.dicebear.com/9.x/avataaars/svg?seed=bradtraversy',
  enrolledCourses: [],
}

Courses

The seed script creates 10 comprehensive courses with real video URLs:

Full-Stack Web Development

Educator: Brad Traversy
Price: ₹3,999 (30% off)
Chapters: 3 | Lectures: 8 | Duration: 177 min
Students: 37

Data Science & ML

Educator: Brad Traversy
Price: ₹4,499 (20% off)
Chapters: 2 | Lectures: 5 | Duration: 120 min
Students: 42

UI/UX Design

Educator: Corey Schafer
Price: ₹2,999 (15% off)
Chapters: 2 | Lectures: 5 | Duration: 115 min
Students: 27

TypeScript Masterclass

Educator: Jeff Delaney
Price: ₹2,499 (20% off)
Chapters: 2 | Lectures: 5 | Duration: 104 min
Students: 32

DevOps with Docker & K8s

Educator: Nana Janashia
Price: ₹3,499 (25% off)
Chapters: 2 | Lectures: 5 | Duration: 128 min
Students: 30

React Native

Educator: Jeff Delaney
Price: ₹3,299 (10% off)
Chapters: 2 | Lectures: 5 | Duration: 104 min
Students: 24
server/seed.js:104-213
{
  courseTitle: 'Full-Stack Web Development with React & Node.js',
  courseDescription: '## Master modern full-stack development\n\nLearn to build...',
  courseThumbnail: 'https://images.unsplash.com/photo-1627398242454-45a1465c2479?w=800&q=80',
  coursePrice: 3999,
  isPublished: true,
  discount: 30,
  educatorId: 'user_seed_educator1',
  courseContent: [
    {
      chapterId: 'ch_react_basics',
      chapterOrder: 1,
      chapterTitle: 'React Fundamentals',
      chapterContent: [
        {
          lectureId: 'lec_jsx',
          lectureTitle: 'JSX and Components',
          lectureDuration: 18,
          lectureUrl: 'https://www.youtube.com/watch?v=SqcY0GlETPk',
          isPreviewFree: true,
          lectureOrder: 1,
        },
        // ... more lectures
      ],
    },
    // ... more chapters
  ],
  courseRatings: [
    { userId: 'user_seed_student1', rating: 5 },
    { userId: 'user_seed_student2', rating: 4 },
  ],
  averageRating: 3.7,
  totalRatings: 12,
  totalLectures: 8,
  totalDurationMinutes: 177,
  enrolledStudents: ['user_seed_student1', 'user_seed_student2', ...],
  totalEnrolledStudents: 37,
}
All courses use real educational YouTube videos. Video URLs point to actual tutorials (not placeholders).

Quizzes

Each course chapter includes a quiz with 2-3 questions:
server/seed.js:1349-1384
{
  courseId: courseWeb._id.toString(),
  chapterId: 'ch_react_basics',
  chapterTitle: 'React Fundamentals',
  courseTitle: 'Full-Stack Web Development with React & Node.js',
  questions: [
    {
      question: 'What hook is used to manage local state in a React functional component?',
      options: ['useEffect', 'useState', 'useRef', 'useContext'],
      correctIndex: 1,
      explanation: 'useState returns a stateful value and a setter function.',
    },
    {
      question: 'Which of the following correctly describes JSX?',
      options: [
        'A CSS preprocessor',
        'A JavaScript XML syntax extension',
        'A Node.js module',
        'A database query language',
      ],
      correctIndex: 1,
      explanation: 'JSX allows writing HTML-like syntax inside JavaScript files.',
    },
    // ... more questions
  ],
}
Total: 15 quizzes across all course chapters.

Community Groups

Four official community groups for discussions:

🌐 Web Development

128 members
HTML, CSS, JavaScript, React, Node.js

🤖 Data Science & AI

94 members
ML, data analysis, Python, AI

🎨 UI/UX Design

76 members
Design systems, Figma, user research

💼 Career & Jobs

210 members
Resume tips, interviews, job hunting
server/seed.js:910-951
{
  name: 'Web Development',
  slug: 'web-development',
  description: 'Discuss HTML, CSS, JavaScript, React, Node.js and everything web.',
  icon: '🌐',
  memberCount: 128,
  postCount: 0,
  createdBy: 'system',
  isOfficial: true,
}

Purchases & Progress

  • 19 completed purchases linking students to courses
  • 19 course progress records tracking which lectures each student has completed
  • Realistic progress percentages (some courses 100% complete, others partially watched)
server/seed.js:1038-1047
{
  courseId: courseWeb._id,
  userId: 'user_seed_student1',
  amount: 2799,
  currency: 'INR',
  providerOrderId: 'order_seed_001',
  providerPaymentId: 'pay_seed_001',
  status: 'completed',
}
server/seed.js:1216-1223
{
  userId: 'user_seed_student1',
  courseId: courseWeb._id.toString(),
  completed: false,
  lectureCompleted: ['lec_jsx', 'lec_hooks', 'lec_express_setup'],
}

Seed Script Deep Dive

How It Works

The seed script follows this flow:
1

Connect to database

server/seed.js:7-9
import connectDB from './configs/mongodb.js'
await connectDB()
2

Clear existing seed data

server/seed.js:959-969
await Promise.all([
  User.deleteMany({ _id: { $regex: /^user_seed_/ } }),
  Course.deleteMany({ educatorId: { $in: ['user_seed_educator1', ...] } }),
  Purchase.deleteMany({ userId: { $regex: /^user_seed_/ } }),
  // ... more deletions
])
Only deletes records with _id starting with user_seed_ or educatorId matching seed educators. Your real data is safe.
3

Insert users

server/seed.js:972-974
const createdUsers = await User.insertMany(users)
console.log(`   ✓ ${createdUsers.length} users`)
4

Insert courses

server/seed.js:977-979
const createdCourses = await Course.insertMany(courseData)
console.log(`   ✓ ${createdCourses.length} courses`)
5

Update users with enrolled courses

server/seed.js:995-1007
await User.updateOne(
  { _id: 'user_seed_student1' },
  {
    enrolledCourses: [
      courseWeb._id,
      courseUX._id,
      // ...
    ],
  }
)
6

Insert purchases, progress, quizzes, groups, posts, replies

Each collection is populated sequentially with insertMany().

Source Code Location

The seed script is located at:
server/seed.js
Key sections:
  • Lines 21-92: User data
  • Lines 104-906: Course data (10 courses with full content)
  • Lines 908-951: Community group data
  • Lines 955-1700+: Main seed function
server/seed.js:1-18
/**
 * Seed script — populates the SkillRise database with demo data.
 * Run: node seed.js
 * Safe to re-run: clears existing seeded collections first.
 */

import 'dotenv/config'
import mongoose from 'mongoose'
import connectDB from './configs/mongodb.js'
import User from './models/User.js'
import Course from './models/Course.js'
import Purchase from './models/Purchase.js'
import CourseProgress from './models/CourseProgress.js'
import CommunityPost from './models/CommunityPost.js'
import Group from './models/Group.js'
import Reply from './models/Reply.js'
import Quiz from './models/Quiz.js'

Customizing Seed Data

To modify the seed data:
1

Open seed.js

cd server
nano seed.js
# or use your preferred editor
2

Modify data arrays

Edit the data arrays at the top of the file:
const users = [
  {
    _id: 'user_seed_educator1',
    name: 'Your Name',
    email: 'your@email.com',
    // ...
  },
  // Add more users
]

const courseData = [
  {
    courseTitle: 'Your Custom Course',
    coursePrice: 1999,
    // ...
  },
  // Add more courses
]
3

Re-run seed script

npm run seed
const users = [
  // ... existing users
  {
    _id: 'user_seed_educator8',
    name: 'Jane Developer',
    email: 'jane@example.com',
    imageUrl: 'https://api.dicebear.com/9.x/avataaars/svg?seed=janedeveloper',
    enrolledCourses: [],
  },
]
const courseData = [
  // ... existing courses
  {
    courseTitle: 'Advanced GraphQL',
    courseDescription: '## Master GraphQL APIs\n\nLearn schema design, resolvers, and more.',
    courseThumbnail: 'https://images.unsplash.com/photo-1234567890?w=800&q=80',
    coursePrice: 2999,
    isPublished: true,
    discount: 10,
    educatorId: 'user_seed_educator1',
    courseContent: [
      {
        chapterId: 'ch_graphql_basics',
        chapterOrder: 1,
        chapterTitle: 'GraphQL Fundamentals',
        chapterContent: [
          {
            lectureId: 'lec_graphql_intro',
            lectureTitle: 'Introduction to GraphQL',
            lectureDuration: 20,
            lectureUrl: 'https://www.youtube.com/watch?v=example',
            isPreviewFree: true,
            lectureOrder: 1,
          },
        ],
      },
    ],
    courseRatings: [],
    averageRating: 0,
    totalRatings: 0,
    totalLectures: 1,
    totalDurationMinutes: 20,
    enrolledStudents: [],
    totalEnrolledStudents: 0,
  },
]

Verify Seeded Data

Using MongoDB Shell

# Connect to MongoDB
mongosh

# Switch to SkillRise database
use SkillRise

# Count seeded users
db.users.countDocuments({ _id: { $regex: /^user_seed_/ } })
# Expected: 10

# List seeded courses
db.courses.find({ educatorId: { $in: ['user_seed_educator1', 'user_seed_educator2'] } }).count()
# Expected: 10

# View a sample user
db.users.findOne({ _id: 'user_seed_student1' })

# View a sample course
db.courses.findOne({ educatorId: 'user_seed_educator1' })

Using the Application

1

Start the application

# Terminal 1
cd server && npm run server

# Terminal 2
cd client && npm run dev
2

Browse seeded content

  1. Open http://localhost:5173
  2. Navigate to Courses → See 10 seeded courses
  3. Navigate to Community → See 4 groups
  4. Sign up with Clerk → Your account is separate from seed data
Seed data uses hardcoded IDs like user_seed_educator1. Real users from Clerk will have different IDs (e.g., user_2abc...).

Resetting Data

To clear all seeded data:
The seed script automatically clears existing seed data before inserting new records:
npm run seed

Troubleshooting

Symptom: Script runs but never completesSolutions:
  1. Check MongoDB connection:
    mongosh $MONGODB_URI/SkillRise --eval "db.stats()"
    
  2. Verify MONGODB_URI in server/.env
  3. Increase connection timeout:
    server/configs/mongodb.js
    await mongoose.connect(`${process.env.MONGODB_URI}/SkillRise`, {
      serverSelectionTimeoutMS: 10000,
    })
    
Error: E11000 duplicate key error collection: SkillRise.users index: _id_ dup keyCause: Seed data already exists in the database.Solutions:
  1. The seed script should auto-clear. Verify lines 959-969 in seed.js
  2. Manually delete conflicting records (see Resetting Data)
Symptom: Seed completes successfully but app shows no coursesSolutions:
  1. Verify you’re connected to the correct database:
    mongosh $MONGODB_URI/SkillRise --eval "db.courses.countDocuments()"
    
  2. Check that courses are marked as published:
    db.courses.find({ isPublished: true }).count()
    
  3. Restart the server:
    cd server && npm run server
    
Symptom: Courses load but lecture videos show “Video unavailable”Cause: YouTube URLs may be region-restricted or removed.Solutions:
  1. This is expected for demo data (videos are real but may have geo-restrictions)
  2. Replace with your own video URLs in seed.js:104-906
  3. Use a different video platform (Cloudinary, Vimeo, etc.)

Production Considerations

Never run the seed script in production. It’s intended for development and testing only.

Safe Production Data Loading

For production, use migration scripts instead:
1

Create migration script

server/migrations/001-initial-courses.js
import Course from '../models/Course.js'

export async function up() {
  await Course.insertMany([
    // Your production courses
  ])
}

export async function down() {
  await Course.deleteMany({ /* your criteria */ })
}
2

Run migration

node migrations/001-initial-courses.js
Consider using a migration tool like migrate-mongo for production deployments.

Next Steps