Я получаю сообщение об ошибке при вводе информации в форму e js в моем веб-приложении, относящейся к моей схеме mongoDB:
Я получаю ошибку:
ValidationError: Subscriber validation failed: grade1: Path `grade1` is required., grade2: Path `grade2` is required., grade3: Path `grade3` is required., grade4: Path `grade4` is required.
my Схема подписчика:
const mongoose = require("mongoose");
const subscriberSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
grade1: {
type: String,
required: true
},
grade2: {
type: String,
required: true
},
grade3: {
type: String,
required: true
},
grade4: {
type: String,
required: true
}
});
subscriberSchema.methods.getInfo = function() {
return `Name: ${this.name} grade1: ${this.grade1} grade2: ${this.grade2} grade3: ${this.grade3} grade4: ${this.grade4}`;
};
subscriberSchema.methods.findLocalSubscribers = function() {
return this.model("Subscriber")
.find({
name: this.name
})
.exec();
};
форма e js:
<div class="col-sm-6">
<h1>Enter Student Name and Grades</h1>
<p>Enter the student's name and grades for the first 4 CSC courses:</p>
<form class="subscription-form" action="/subscribers/create" method="post">
<input type="text" name="name" placeholder="Name" autofocus>
<input type="text" grade1="grade1" placeholder="CSC141 Grade" required>
<input type="text" grade2="grade2" placeholder="CSC142 Grade" required>
<input type="text" grade3="grade3" placeholder="CSC240 Grade" required>
<input type="text" grade4="grade4" placeholder="CSC241 Grade" required>
<input type="submit" name="submit">
</form>
</div>
подписчики / создать в контроллере подписчиков:
create: (req, res, next) => {
let subscriberParams = {
name: req.body.name,
grade1: req.body.grade1,
grade2: req.body.grade2,
grade3: req.body.grade3,
grade4: req.body.grade4
};
Subscriber.create(subscriberParams)
.then(subscriber => {
res.locals.redirect = "/subscribers";
res.locals.subscriber = subscriber;
next();
})
.catch(error => {
console.log(`Error saving subscriber: ${error.message}`);
next(error);
});
},
...
Я новичок mongoDB / nodejs / e js, поэтому мне интересно, что я делаю не так.