NodeJS – MongooseJS架构错误,我无法弄清楚

也许第二组眼睛可以看到我的模式有什么问题

var UserSchema = new Schema({ name: { first : {type: String} , last : {type : String} } , password: {type: String} , username: {type: String} , role: RoleSchema , created_at : {type : Date, default : Date.now} , modified_at : {type : Date, default : Date.now} }) var RoleSchema = { type: [String] , study_type: [String] } mongoose.model('User', UserSchema) 

错误:

 TypeError: Invalid value for schema path `role` 

embedded式架构(angular色)需要在UserSchema之上

除了必须在UserSchema之前导入angular色模式之外。

在较新版本的mongoose中,还需要以下语法才能超出'TypeError: Invalid value for schema Array path

 var SomeSchema = new mongoose.Schema(); SomeSchema.add({ key1: { type: String, required: true }, key2: { type: String, required: true }, key3: { type: String, required: true } }); SomeSchema.get(function(val){ // Remove the _id from the Violations delete val._id; return val; }); 

而父母:

 var ParentSchema = new mongoose.Schema({ parentKey: String, someArray: [SomeSchema] }) module.exports = mongoose.model('Parent', ParentSchema) 

当从mongoose3.x切换到4.x时发生这种情况