First, here is the code:
Mongoose Schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// Registration Form schema
var RegistrationFormSchema = new Schema;
RegistrationFormSchema.add({
studentFirst: { type: String, required: true },
studentLast: { type: String, required: true },
studentGrade: { type: String, required: true },
guardianFirst: { type: String, required: true },
guardianLast: { type: String },
guardianEmail: { type: String },
courseString: { type: String },
courseArray: { type: Array }
});
module.exports = mongoose.model('RegistrationForm', RegistrationFormSchema);
Relevant API Route
apiRouter.route('/registerNow')
.post(function(req, res) {
var newForm = new RegistrationForm();
console.log(req.body);
newForm.studentFirst = req.body.studentFirst;
newForm.studentLast = req.body.studentLast;
newForm.studentGrade = req.body.studentGrade;
newForm.guardianFirst = req.body.guardianFirst;
newForm.guardianLast = req.body.guardianLast;
newForm.guardianEmail = req.body.guardianEmail;
newForm.courseString = req.body.courseString;
newForm.save();
}
And this is inside of my controller, where I am making the request. Also making a request in Postman with the same response, so not sure if it is anything to do with how I am requesting, but want to include this to have more info for an answer.
$http.post('/api/registerNow', {
'studentFirst': vm.courseInfo.studentFirst,
'studentLast': vm.courseInfo.studentLast,
'studentGrade': vm.courseInfo.studentGrade,
'guardianFirst': vm.courseInfo.guardianFirst,
'guardianLast': vm.courseInfo.guardianLast,
'guardianEmail': vm.courseInfo.guardianEmail,
'courseString': vm.courseInfo.courseString,
'courseArray': ['asdasd', 'fasfasf', 'gasgasga']
});
Now that we have the relevant code, the question!
When I make my HTTP Post request to save to my database, it all saves, but it saves courseArray as an empty array '[]' no matter what, if it is empty or full.
I assume it's a Mongoose Schema issue.