2017-06-06 95 views
0

添加新键我有一个像MongoDB的:不能在嵌套的对象

var schema = new mongoose.Schema({ 
    agentCode: String, 
    data: { 
    type: Object, 
    profDtl: { 
     education: String  
    } 
}); 

MongoDB中的模式现在我想在profDtl

var schema = new mongoose.Schema({ 
    agentCode: String, 
    data: { 
    type: Object, 
    profDtl: { 
     desgnName: String, // trying to add new property 
     education: String  
    } 
}); 

增加新属性desgnName但它不是反映在数据库中

回答

0

我得到了一个解决方案,无论何时在mongodb模式中添加新属性,它都需要默认值反映新条目

为如:

var schema = new mongoose.Schema({ 
    agentCode: String, 
    data: { 
    type: Object, 
    profDtl: { 
     desgnName: { 
     type: String, 
     default: "" 
     }, 
     education: String  
    } 
}); 

现在它工作正常