Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.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_Mongodb_Rest_Express_Mongoose - Fatal编程技术网

Node.js 无法修改Mongoose文档搜索中的对象

Node.js 无法修改Mongoose文档搜索中的对象,node.js,mongodb,rest,express,mongoose,Node.js,Mongodb,Rest,Express,Mongoose,我正在尝试创建一个通用REST,它返回给定模式的所有记录 /* Read all entries for a given document type, TODO: limit this to a sensible amount of records, say 500 */ app.get( '/data/all/:id' , verifySession , function( req, res ) { exposed[req.params.id].find( {} , f

我正在尝试创建一个通用REST,它返回给定模式的所有记录

  /* Read all entries for a given document type, TODO: limit this to a sensible amount of records, say 500 */  
  app.get( '/data/all/:id' , verifySession , function( req, res )
  {
    exposed[req.params.id].find( {} , function(err,docs)
    { 
      if( docs && req.params.id == "Account" )
        docs.forEach( function(o){ console.log(o); delete o.salt; delete o.hash; console.log(o); } );
        res.json( err || docs ); 
    });     
  });
对于帐户,我不想返回
散列
,但是o的行为就像它是只读的一样。第二个console.log(o)仍然有
salt
hash


帮助?

Mongoose返回不是普通对象的文档实例

因此,您需要首先使用以下方法转换它们:

或者,您可以告诉
find
排除结果中的
hash
salt
字段:

exposed[req.params.id].find({}, '-hash -salt', function(err, docs) { ... });
exposed[req.params.id].find({}, '-hash -salt', function(err, docs) { ... });