Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js NodeJS-MongooseJS模式错误,我无法理解_Node.js_Mongoose - Fatal编程技术网

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时发生的