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

164
Views
ExpressJS/MongoDB : ValidationError: List validation failed: title: Path `title` is required

hello i'm new to Express and mongoDB, I'm creating a task manager application and I'm stuck on an error, when i run nodemon app.js i have this error in terminal and the error seems to come from the post method,can you help me please

The message:

ValidationError: List validation failed: title: Path `title` is required. at model.Document.invalidate (C:\Users\Ned\Workspace\task-manager\api\node_modules\mongoose\lib\document.js:2943:32) at C:\Users\Ned\Workspace\task-manager\api\node_modules\mongoose\lib\document.js:2734:17 at C:\Users\Ned\Workspace\task-manager\api\node_modules\mongoose\lib\schematype.js:1325:9

Here is my:

  • list.model.js
const mongoose = require('mongoose');

const ListSchema = new mongoose.Schema({
    title: {
        type: String,
        required: true,
        minlength: 1,
        trim: true
    }


})

const List = mongoose.model('List', ListSchema);

module.exports = { List }
  • task.model.js

const mongoose = require('mongoose');

const TaskSchema = new mongoose.Schema({
    title: {
        type: String,
        required: true,
        minlength: 1,
        trim: true
    },
    _listId: {
        type: mongoose.Types.ObjectId,
        required: true
    }
})

const Task = mongoose.model('Task', TaskSchema);

module.exports = { Task }

  • And my app.js :
const express  = require('express');
const app = express();

const {mongoose} = require('./db/mongoose')

const bodyParser = require('body-parser');

// Load in the mogoose models
const { List, Task } = require('./db/models');


// Load middleware
app.use(bodyParser.json());


// ROUTES HANDLERS

// LIST ROUTES

/**
 * GET /lists
 * Pupose: Get all lists
 */
app.get('/lists', (req, res) => {
    // Return an array of all lists in the database
    List.find({}).then((lists) => {
      res.send(lists);
    })
});


/**
 * POST /lists
 * Purpose: Create a list
 */
app.post('/lists', (req, res) => {
    // Create a new list and return the new list document back to the new user (which includes the id)
    // The list information (fields) will be passed via the JSON request body
    let title = req.body.title;

    let newList = new List({
      title
    });
    newList.save().then((listDoc) => {
      // The full list document is returned (incl. id)
      res.send(listDoc);
    })
});



app.listen(3000, () => {
    console.log('Server in listening on port 3000');
})

the error seems to come from the post method when i try to create a new list. help please ^^

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!