2016-11-18 16 views
0

我是Mongoose和nodejs的新手。試圖做一個簡單的項目。我試圖創建一個具有以下字段的模式。我試圖在前端和JSON中對它進行字符串化。在後端對它進行解析。 我收到一個錯誤「cast to array failed for value」。以下架構模型是否正確聲明?

var studentSchema = new Schema({ 
 
     
 
    profileNum    : {type:String}, 
 
    eMail     : {type:String}, 
 
\t preferredLocation \t  : [], 
 
\t gender \t     : {type:String,default:''}, 
 
\t education    : [{institute:String,batch:Number,course:String}], 
 
\t profession    : [], 
 
\t designation    : {type:String,default:''}, 
 
\t organization   : {type:String,default:''} \t 
 

 
});

+0

你從哪裏得到那個錯誤? – DevDig

+0

@DevDig在angular的前端,我正在執行這個'$ scope.education = JSON.stringify($ scope.education);'然後發送數據。在後端執行此操作'var educationDetail = req.body.education;教育詳細信息= JSON.parse(educationDetail); result.education = educationDetail;' – puneeth8994

+0

'$ scope.education'看起來像什麼? – str

回答

0

爲了您education路徑,您可能要麼使用[Schema.Types.Mixed]或創建子文檔的教育新模式,並使用[EducationSchema]如果你需要的類型或其他中間件/驗證。

相關問題