Saving Model in Mongoose fails to save nested component

前端 未结 1 1276
甜味超标
甜味超标 2021-01-26 12:41

I have the following model schema:

var memberSchema = mongoose.Schema({

    \'project\'       : { 
        \'type\'      : Schema.Types.ObjectId, 
        \'ref         


        
1条回答
  •  猫巷女王i
    2021-01-26 13:34

    To define a field in an embedded object named type, you need to use the object notation to define its type or Mongoose thinks it's defining the type of the parent object.

    So change your schema to:

    var memberSchema = mongoose.Schema({
    
        'project'       : { 
            'type'      : Schema.Types.ObjectId, 
            'ref'       : 'Project' 
        },
        'first'         : String,
        'last'          : String,
        'email'         : String,
        'tracker'       : {
            'etag'      : String,
            'id'        : String,
            'photoLink' : String,
            'role'      : String,
            'type'      : {'type': String},   // Here...
        },
        'survey'        : {
            'etag'      : String,
            'id'        : String,
            'photoLink' : String,
            'role'      : String,
            'type'      : {'type': String},   // ...and here
        },
    });
    

    0 讨论(0)
提交回复
热议问题