Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何清除mongoose验证错误_Node.js_Mongoose - Fatal编程技术网

Node.js 如何清除mongoose验证错误

Node.js 如何清除mongoose验证错误,node.js,mongoose,Node.js,Mongoose,我正在使用mongoose进行验证,我希望将结果传递回客户端。mongoose为错误提供的JSON blob几乎正是我所需要的,但它有一些额外的东西: errors: { username: { [ValidatorError: Path `username` is required.] properties: [Object], message: 'Path `username` is required.', name: 'ValidatorE

我正在使用mongoose进行验证,我希望将结果传递回客户端。mongoose为错误提供的JSON blob几乎正是我所需要的,但它有一些额外的东西:

errors: 
 { username: 
    { [ValidatorError: Path `username` is required.]
      properties: [Object],
      message: 'Path `username` is required.',
      name: 'ValidatorError',
      kind: 'required',
      path: 'username',
      value: undefined } } }

客户端不需要
username.properties
字段。我知道我可以
删除username.properties
,但是有更好的方法清理JSON吗?

使用
lodash

var _ = require('lodash');

yourMongooseError = _.mapValues(yourMongooseError, function(field) {
  return _.omit(field, ['properties']); // add any other props that you want to remove from each field
});