2015-09-10 45 views
0

我是結構化的數據驗證有我使用的是自動窗體一些簡單的模式:流星 - 與簡單模式/自動窗體

Schemas.studentRecord = new SimpleSchema({ 
    'common.FName': {  // note that this field is nested 
     type: String, 
     optional: false, 
     label: "First Name", 
     max: 50 
    } 
}); 

插入使用該架構的正常工作的文件。更新它也是。問題是,當我嵌套數據可選:false驗證沒有運行,它只是被忽略 - 這意味着我可以插入空白文檔。但是使用下面的模式,而不嵌套它的工作原理:

Schemas.studentRecord = new SimpleSchema({ 
    'commonFName': {  // note that this field is no longer nested 
     type: String, 
     optional: false, 
     label: "First Name", 
     max: 50 
    } 
}); 

所以我的問題是,我可以驗證嵌套數據,或者我必須保持它的非結構化進行驗證?

回答

1

解決方案是包括「共同」作爲模式的一部分:

'common': { 
type: Object 
}