NodeJS MissingSchemaError:架构尚未为模型“Emp”注册

a64a0gku  于 9个月前  发布在  Node.js
关注(0)|答案(1)|浏览(167)

我已经尝试了不同的解决方案,但无法解决这个问题。
这是我的代码

var mongoose = require('mongoose');

var schema = new mongoose.Schema({
    name:{
        type:String,
        required:true
    },
    email:{
        type:String,
        required:true,
        lowercase:true
    }
});
mongoose.connect('mongodb://localhost:27017/test');
//parameters are model name,schema,collection name
var Emp = mongoose.model('Emp','schema','users');

字符串

jobtbby3

jobtbby31#

您正在model方法的第二个参数中使用字符串,并且它需要Schema。
这解决了你的问题:

var Emp = mongoose.model('Emp',schema,'users');

字符串
以下是您必须使用的参数类型:用途:

name         String   model name

schema       Schema

collection   String   name (optional, induced from the model name)

skipInit    Boolean whether to skip initialization (defaults to false)


更多信息请访问:http://mongoosejs.com/docs/api.html#index_Mongoose-model

相关问题