Mutating data in the graphql playground says the message of Message: Student is not a constructor Error: "TypeError: Student is not a constructor" Student is my Mongoose Model.
I've tried reinstalling my node_modules, searching some fix on the github.
This is my Mutation Function
addStudent: async (
root,
{ studentId, firstName, lastName, email, password },
{ Student }
) => {
const newStudent = await new Student({
studentId,
firstName,
lastName,
email,
password
}).save();
return newStudent;
}
and this is my Mongoose Model
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const StudentSchema = new Schema({
studentId: {
type: String,
required: true
},
firstName: {
type: String,
required: true
},
lastName: {
type: String,
required: true
},
// sectionId: {
// type: [Schema.Types.ObjectId],
// ref: "Section",
// nullable: true
// },
email: {
type: String,
required: true
},
password: {
type: String,
required: true
},
createdDate: {
type: Date,
default: Date.now
}
});
module.exports = mongoose.model("Student", StudentSchema);
The student should be created, but that error pops up with that message.