Mongoose error: TypeError: schema is not a constructor? in Node

problem description

create a student Schame, with mongoose but report an error at run time, the error is in the Schema; of the third line

TypeError: schema is not a constructor

looked at the code did not find a mistake, please help to have a look, thank you!

related codes

var mongoose = require("mongoose"),
    Schema = mongoose.Schema;
const courseInf = new Schema({
    teacher:String,
    courseName:String
});
const student = new Schema({
    name:String,                //
    class:String,                //
    stunum:String,                //
    oldpassword:String,           //
    newpassword:String,           //
    phonenum:String,              //
    course:[courseInf]           //
});

module.exports.stu = mongoose.model("student",student);
Apr.22,2021

try to replace Schema = mongoose.Schema; with const {Schema} = mongoose;


this file should have no problem, feel that the location of the file you located is wrong, it is best to post the error message.
Please search globally to see if there are places where Schema = new mongoose.Schema; , that is, an extra new

has been written.
Menu