Node.js NodeJS-MongooseJS模式错误,我无法理解
也许第二双眼睛可以看出我的模式有什么问题Node.js NodeJS-MongooseJS模式错误,我无法理解,node.js,mongoose,Node.js,Mongoose,也许第二双眼睛可以看出我的模式有什么问题 var UserSchema = new Schema({ name: { first : {type: String} , last : {type : String} } , password: {type: String} , username: {ty
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`
除了必须在UserSchema之前导入的角色模式之外,嵌入式模式(角色)还需要位于UserSchema之上 在较新版本的mongoose中,还需要以下语法来超越
”类型错误:架构数组路径的值无效:
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时发生的