鍍金池/ 問(wèn)答/數(shù)據(jù)庫(kù)  HTML/ Node中 mongoose報(bào)錯(cuò):TypeError: schema is no

Node中 mongoose報(bào)錯(cuò):TypeError: schema is not a constructor?

問(wèn)題描述

用mongoose創(chuàng)建了一個(gè)學(xué)生Schame,但是運(yùn)行的時(shí)候報(bào)錯(cuò),錯(cuò)誤在第三行的Schema;

TypeError: schema is not a constructor

看了代碼沒(méi)找到錯(cuò),請(qǐng)大家?guī)兔纯?,謝謝!

相關(guān)代碼

var mongoose = require('mongoose'),
    Schema = mongoose.Schema;
const courseInf = new Schema({
    teacher:String,
    courseName:String
});
const student = new Schema({
    name:String,                //姓名
    class:String,                //班級(jí)
    stunum:String,                //學(xué)號(hào)
    oldpassword:String,           //舊密碼
    newpassword:String,           //新密碼
    phonenum:String,              //手機(jī)號(hào)
    course:[courseInf]           //課程
});

module.exports.stu = mongoose.model('student',student);
回答
編輯回答
孤巷

試試把Schema = mongoose.Schema;換成 const { Schema } = mongoose;

2018年9月7日 08:21
編輯回答
任她鬧

這個(gè)文件應(yīng)該沒(méi)有問(wèn)題,感覺(jué)你定位的文件位置不對(duì),最好將錯(cuò)誤信息貼出來(lái)。
請(qǐng)全局搜索一下,是不是有的地方這樣寫(xiě)的 Schema = new mongoose.Schema;,即多寫(xiě)了一個(gè)new

2018年7月22日 11:53