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:
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 }
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 }
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 ^^