Javascript mongoose必填字段嵌套模式

Javascript mongoose必填字段嵌套模式,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我正试图使用mongoose 4.4.6在嵌套模式上创建一个必填字段,但从未收到验证错误。。这是我的最小非工作代码: models/Test.js: var mongoose = require('mongoose'); var TestChildSchema = mongoose.Schema({ _id: false, testRequiredField: {type: String, required: true} }); var TestParentSchema =

我正试图使用mongoose 4.4.6在嵌套模式上创建一个必填字段,但从未收到验证错误。。这是我的最小非工作代码:
models/Test.js:

var mongoose = require('mongoose');

var TestChildSchema = mongoose.Schema({
    _id: false,
    testRequiredField: {type: String, required: true} 
});

var TestParentSchema = mongoose.Schema({
    testField: TestChildSchema
});

module.exports = mongoose.model('Test', TestParentSchema);
我是这样使用的:
page.js

var mongoose = require( 'mongoose' );
var Test = mongoose.model('Test');

exports.index = function (req, res) {
  var test = new Test();
  test.save(function (err, test) {
    var strOutput; 
     res.writeHead(200, { 
       'Content-Type': 'text/plain'
     }); 
     if (err) { 
       console.log(err); 
       strOutput = 'Oh dear, we\'ve got an error'; 
     } else { 
       console.log('test created: ' + test); 
       strOutput = 'Success'; 
     } 
     res.write(strOutput); 
     res.end(); 
  });
和我的app.js

var http = require('http');  
var mongoose = require('mongoose'); 
var dbURI = 'mongodb://localhost:27017/ConnectionTest'; 
mongoose.connect(dbURI); 
require('./models/Test');
var pages = require('./pages');

http.createServer(function (req, res) {  
  pages.index(req, res);
}).listen(8888, '127.0.0.1');

为什么此代码不会在嵌套的必填字段上生成验证错误?是否有其他方法生成验证错误?我错过什么了吗

因为testRequiredField在
var test=new test()之后未定义

如果我的字段未定义,他不应该生成验证错误,因为我希望它是必需的吗?