Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

900
Views
I get this error: this.$__.validationError = new ValidationError(this)

I am new to learning web dev using node.js and express.js. When I test my code in Postman the server crashes and gives me this error this.$__.validationError = new ValidationError(this). I am creating backend server connected to MongoDB and the mongoose package.

Routes

const express = require('express')
const router = express.Router()

const {
    create

} = require('./../controllers/courseControllers')

const {verifyAdmin, verify} = require('./../auth')


router.post('/create', verifyAdmin, async (req, res) => {
    // console.log(req.body)
    try{
        create(req.body).then(result => res.send(result))

    }catch(err){
        res.status(500).json(err)
    }
})

Controllers

const Course = require('../models/Course');


//CREATE A COURSE
module.exports.create = async (reqBody) => {
    const {courseName, description, price} = reqBody

    let newCourse = new Course({
        courseName: courseName,
        description: description,
        price: price
    })
    // console.log(newCourse)
    return await newCourse.save().then((result, err) => result ? result : err)
}

Schema

const mongoose = require('mongoose');

const courseSchema = new mongoose.Schema({
    courseName: {
        type: String,
        required: [true, `Course name is required`],
        unique: true
    },
    description: {
        type: String,
        required: [true, `Course description is required`]
    },
    price: {
        type: Number,
        required: [true, `Price is required`]
    },
    isOffered: {
        type: Boolean,
        default: true
    },
    enrollees: [
        {
            userId: {
                type: String,
                required: [true, `userId is required`]
            },
            enrolledOn: {
                type: Date,
                default: new Date()
            }
        }
    ]
}, {timestamps: true})

module.exports = mongoose.model("Course", courseSchema);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!