为了账号安全,请及时绑定邮箱和手机立即绑定

NodeJs报错 Error:can't set headers after they are sent

NodeJs报错 Error:can't set headers after they are sent

swust_li 2017-10-31 12:23:03
Post.getOne = function(name,day,title,callback){ //打开数据库 mongodb.open(function(err,db){ if (err) { return callback(err);//错误,返回err信息 } //读取posts 集合 db.collection('posts',function(err,collection){ if (err) { mongodb.close(); return callback(err);//错误,返回err信息 } //根据用户名、发表日期及文章名进行查询 collection.findOne({ "name": name, "time.day": day, "title": title },function(err,doc){ mongodb.close(); if (err) { return callback(err);//错误,返回err信息 } if(doc){ //每访问1次,pv值增加1 collection.update({ "name":name, "time.day":day, "title":title },{ $inc:{"pv":1} },function(err){ mongodb.close(); if (err) { return callback(err); } }); //解析markedown为html doc.post = markdown.toHTML(doc.post); if(doc.comments){ doc.comments.forEach(function(comment){ comment.content = markdown.toHTML(comment.content); }); } callback(null,doc);//成功!err为null,并返回存储后的用户文档 } }); }); }); }; //好像是在查询里面包含了update,然后就报这个错了。请问各位大神这个问题怎么解决?或者怎么在查询里更新数据?
查看完整描述

目前暂无任何回答

  • 0 回答
  • 1 关注
  • 1517 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信