Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.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$inc findByIdAndUpdate失败_Node.js_Mongoose_Auto Increment_Put - Fatal编程技术网

Node.js mongoose$inc findByIdAndUpdate失败

Node.js mongoose$inc findByIdAndUpdate失败,node.js,mongoose,auto-increment,put,Node.js,Mongoose,Auto Increment,Put,当我更新一个对象rappel时,我想自动增加一个attribute modif(modif是一个计数器,每次更新都应该增加1)。但是当我使用mongoose的$inc时,它工作正常,然后失败了 /routes/rappels.js /* update rappel by autoincrement modif {$inc: { modif: 1} }*/ router.put('/:id', function(req, res, next) { //var data

当我更新一个对象rappel时,我想自动增加一个attribute modif(modif是一个计数器,每次更新都应该增加1)。但是当我使用mongoose的$inc时,它工作正常,然后失败了

   /routes/rappels.js
   /* update rappel by autoincrement modif {$inc: { modif: 1} }*/
    router.put('/:id', function(req, res, next) {
    //var data = req.body;
    //if(data.posts == undefined) data.posts = [];    
    models.rappel.findByIdAndUpdate(req.params.id, 
  {$inc: { modif: 1}},  {new: true}, function(err, c){
    if(err) res.json({error: err});

    res.json(c).send({modif: c.modif});
   });
  });
模型是:

 var mongoose = require('../config/db');

 var RappelSchema = mongoose.Schema({
 titre: String,
 date_rappel: String,
 heure_rappel: String,
 type: String,
 modif: { type: Number, default: 0 },
 suppre: ['0', '1'],
 robot: { type: mongoose.Schema.Types.ObjectId, ref: 'Robot' }
  });

 module.exports = mongoose.model('Rappel', RappelSchema);

 it work fine when I test with Postman but after 2 updates the application failed and crushed.
这是heroku日志的结果

   remote:
   remote: -----> Compressing...
   remote:        Done: 31.2M
   remote: -----> Launching...
   remote: Released v76
   remotte: https://testroomie.herokuapp.com/ deployed to Heroku
   remote:
   remote: Verifying deploy... done.

  Warning: Your console font probably doesn't support Unicode. 
 If you experience strange characters in
 the output, consider switching to a TrueType font such as Consolas!
 To https://git.heroku.com/testroomie.git
 d12e210..9a60555  master -> master

C:\OSC2016\HerokuPull28_08_16\testroomie>heroku logs
2016-09-08T07:42:42.421017+00:00 app[web.1]:at 
ServerResponse.header(/app/node_modules/express
/lib/response.js:718:10)
2016-09-08T07:42:42.421018+00:00 app[web.1]:at 
 ServerResponse.send (/app/node_modules/express/
  lib/response.js:163:12)
  2016-09-08T07:42:42.421018+00:00 app[web.1]:     
  at ServerResponse.json (/app/node_modules/express/
  lib/response.js:249:15)
  2016-09-08T07:42:42.421019+00:00 app[web.1]:     
  at Query.<anonymous>(/app/routes/rappels.js:48:21)


  2016-09-08T07:42:42.421019+00:00 app[web.1]:     
  at ServerResponse.send (/app/node_modules/express/
  lib/response.js:151:21)
  2016-09-08T07:42:42.421020+00:00 app[web.1]:     
  at /app/node_modules/kareem/index.js:177:19
  2016-09-08T07:42:42.421021+00:00 app[web.1]:   
   at /app/node_modules/kareem/index.js:109:16
  2016-09-08T07:42:42.421021+00:00 app[web.1]:    
  at _combinedTickCallback (internal/process/
  next_tick.js:67:7)
  2016-09-08T07:42:42.421022+00:00 app[web.1]:    

  at process._tickCallback (internal/process/
  next_tick.js:98:9)
  2016-09-08T07:42:42.446749+00:00 app[web.1]:
  2016-09-08T07:42:42.463235+00:00 app[web.1]: npm ERR! 
  Linux 3.13.0-93-  generic
  2016-09-08T07:42:42.463766+00:00 app[web.1]: npm ERR! 
  argv"/app/.heroku/node/bin/node" "/app/.herok
  u/node/bin/npm" "start"
  2016-09-08T07:42:42.464078+00:00 app[web.1]: npm ERR! node v5.11.1
  2016-09-08T07:42:42.465018+00:00 app[web.1]: npm ERR! npm  v3.8.6
  2016-09-08T07:42:42.465340+00:00 app[web.1]: npm ERR! code ELIFECYCLE
  2016-09-08T07:42:42.465579+00:00 app[web.1]: npm ERR! 
  PiExpress@0.0.0   start: `node ./bin/www`
  2016-09-08T07:42:42.465815+00:00 app[web.1]: npm ERR! Exit status 1
  2016-09-08T07:42:42.466082+00:00 app[web.1]: npm ERR!
  2016-09-08T07:42:42.466310+00:00 app[web.1]: npm ERR! Failed at 
  the PiExpress@0.0.0 start script 'no
  de ./bin/www'.
  2016-09-08T07:42:42.466535+00:00 app[web.1]: npm ERR! Make sure you 
  have the latest version of
  node.js and npm installed.
  2016-09-08T07:42:42.466747+00:00 app[web.1]: npm ERR! If you do, 
  this is most likely a problem with
  the PiExpress package,
  2016-09-08T07:42:42.466965+00:00 app[web.1]: npm ERR! not with npm itself.
  2016-09-08T07:42:42.467175+00:00 app[web.1]: npm ERR! Tell the author 
  that this fails on your system:
  2016-09-08T07:42:42.467403+00:00 app[web.1]: npm ERR!     node ./bin/www
  2016-09-08T07:42:42.467614+00:00 app[web.1]: npm ERR! You can 
  get information on how to open an issue for this project with:
  2016-09-08T07:42:42.467835+00:00 app[web.1]: npm ERR!npm bugs PiExpress
  2016-09-08T07:42:42.468054+00:00 app[web.1]: npm ERR! Or if that 
  isn't available, you can get their info via:
  2016-09-08T07:42:42.468274+00:00 app[web.1]:npm ERR!npm owner ls PiExpress
  2016-09-08T07:42:42.468492+00:00 app[web.1]: npm ERR! There is 
  likely additional logging output above.
  2016-09-08T07:42:42.473827+00:00 app[web.1]:
  2016-09-08T07:42:42.474143+00:00 app[web.1]: npm ERR! Please include 
  the following file with any support request:
  2016-09-08T07:42:42.474355+00:00 app[web.1]: npm ERR! /app/npm-debug.log
 2016-09-08T07:42:42.578312+00:00 heroku[web.1]:Process exited with status 1
 2016-09-08T07:42:42.613995+00:00 heroku[web.1]: State changed from 
  up to  crashed
  2016-09-08T07:42:42.615056+00:00 heroku[web.1]: State changed from 
   crashed to starting
  2016-09-08T07:42:45.070840+00:00 heroku[web.1]: Starting process 
  with command `npm start`
  2016-09-08T07:42:47.367719+00:00 app[web.1]:
  2016-09-08T07:42:47.367733+00:00 app[web.1]: > PiExpress@0.0.0 start /app
  2016-09-08T07:42:47.367734+00:00 app[web.1]: > node ./bin/www
  2016-09-08T07:42:47.367735+00:00 app[web.1]:
  2016-09-08T07:42:48.034029+00:00 app[web.1]: mongo connected
  2016-09-08T07:42:48.641807+00:00 heroku[web.1]: State changed 
  from starting to up
  2016-09-08T07:43:41.999170+00:00 heroku[router]: at=info 
  method=POST    path="/authenticate/" host=test
  roomie.herokuapp.com 
  request_id=2c5f72c8-e3ac-4797-88b4-2c84301eac87 
  fwd="41.224.13.74"dyno=web.1 connect=1ms service=84ms status=200bytes=1967
  2016-09-08T07:43:41.994683+00:00 app[web.1]: POST /authenticate/ 
 200 70.400   ms - 1559
 2016-09-08T07:44:14.756752+00:00 heroku[router]: 
 at=info method=PUT     path="/rappels/57d03a51f67f121100af8cf3"
 host=testroomie.herokuapp.com 
 request_id=c8db23e5-daf1-46d8-a984-f2bba76db5d9 
 fwd="41.224.13.74"   dyno=web.1 connect=0ms service=24ms 
 status=200 bytes=608
 2016-09-08T07:44:14.772687+00:00 app[web.1]: _http_outgoing.js:346
 2016-09-08T07:44:14.772723+00:00 app[web.1]:throw new Error
 ('Can\'t set  headers after they are sent.');
 2016-09-08T07:44:14.772732+00:00 app[web.1]:     ^
  2016-09-08T07:44:14.772740+00:00 app[web.1]:
  2016-09-08T07:44:14.772749+00:00 app[web.1]: 
  Error: Can't set headers after they are sent.
  2016-09-08T07:44:14.772751+00:00 app[web.1]:
  at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11)
  2016-09-08T07:44:14.772751+00:00 app[web.1]:     
  at ServerResponse.header (/app/node_modules/expres/lib/response.js:718:10)
  2016-09-08T07:44:14.772752+00:00 app[web.1]:     
  at ServerResponse.send(/app/node_modules/express/lib/response.js:163:12)
  2016-09-08T07:44:14.772752+00:00 app[web.1]:     
   at ServerResponse.json (/app/node_modules/express/lib/response.js:249:15)
   2016-09-08T07:44:14.772753+00:00 app[web.1]:     
   at ServerResponse.send (/app/node_modules/express/lib/response.js:151:21)
   2016-09-08T07:44:14.772754+00:00 app[web.1]:     
   at Query.<anonymous> (/app/routes/rappels.js:48:21)

   2016-09-08T07:44:14.772754+00:00 app[web.1]:     
   at /app/node_modules/kareem/index.js:177:19
   2016-09-08T07:44:14.772755+00:00 app[web.1]:     
   at   /app/node_modules/kareem/index.js:109:16
   2016-09-08T07:44:14.772755+00:00 app[web.1]:     
   at _combinedTickCallback (internal/process/next_tick.js:67:7)
   2016-09-08T07:44:14.772764+00:00 app[web.1]:     
    at process._tickCallback (internal/process/next_tick.js:98:9)
     2016-09-08T07:44:14.785178+00:00 app[web.1]:
    2016-09-08T07:44:14.794981+00:00 app[web.1]: npm ERR! 
     Linux 3.13.0-91- generic
     2016-09-08T07:44:14.795427+00:00 app[web.1]: npm ERR! 
     argv   "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
    2016-09-08T07:44:14.795700+00:00 app[web.1]: npm ERR! node v5.11.1
    2016-09-08T07:44:14.796770+00:00 app[web.1]: npm ERR! code ELIFECYCLE
    2016-09-08T07:44:14.796544+00:00 app[web.1]: npm ERR! npm  v3.8.6
    2016-09-08T07:44:14.796979+00:00 app[web.1]: npm ERR! 
    PiExpress@0.0.0 start: `node ./bin/www`
    2016-09-08T07:44:14.797144+00:00 app[web.1]: npm ERR! Exit status 1
    2016-09-08T07:44:14.797351+00:00 app[web.1]: npm ERR!
    2016-09-08T07:44:14.797529+00:00 app[web.1]: npm ERR! 
    Failed at the PiExpress@0.0.0 start script 'node ./bin/www'.
    2016-09-08T07:44:14.797905+00:00 app[web.1]: npm ERR! If you do, 
    this is most likely a problem with the PiExpress package,
    2016-09-08T07:44:14.797720+00:00 app[web.1]: npm ERR! Make sure 
    you have the latest version of node.js and npm installed.
    2016-09-08T07:44:14.798078+00:00 app[web.1]: npm ERR! 
    not with npm itself.
    2016-09-08T07:44:14.798255+00:00 app[web.1]: npm ERR! 
    Tell the author  that this fails on your system:
    2016-09-08T07:44:14.798477+00:00 app[web.1]: npm ERR!     node ./bin/www
    2016-09-08T07:44:14.798671+00:00 app[web.1]: npm ERR! 
    You can get information on how to open an issue for this project with:
    2016-09-08T07:44:14.798849+00:00 app[web.1]: npm ERR!     
   npm bugs PiExpress
   2016-09-08T07:44:14.799041+00:00 app[web.1]: npm ERR! 
   Or if that isn't available, you can get their info via:
   2016-09-08T07:44:14.799211+00:00 app[web.1]: npm ERR!     
  npm owner ls PiExpress
  2016-09-08T07:44:14.799394+00:00 app[web.1]: npm ERR! There is 
  likely   additional logging output above.
  2016-09-08T07:44:14.805265+00:00 app[web.1]:
  2016-09-08T07:44:14.805483+00:00 app[web.1]: npm ERR! Please 
  include the following file with any support request:
  2016-09-08T07:44:14.805611+00:00 app[web.1]: npm ERR!     
  /app/npm-debug.log
  2016-09-08T07:44:14.932783+00:00 heroku[web.1]: State changed 
  from up to crashed
  2016-09-08T07:44:14.933664+00:00 heroku[web.1]: Process exited 
  with status 1
  2016-09-08T07:44:19.222339+00:00 heroku[router]: at=error 
  code=H10 desc="App crashed"
  method=PUT    path="/rappels/57d03a51f67f121100af8cf3" 
  host=testroomie.herokuapp.com request_id=9ffc6580-6d50-4c0d-b4
  06-2dfd96860df2 fwd="41.224.13.74" dyno= connect= service= 
  status=503 bytes=
  2016-09-08T07:45:18.507804+00:00 heroku[router]: at=error 
  code=H10 desc="App crashed" method=GET 
  path="/rappels" host=testroomie.herokuapp.com 
  request_id=9305aa1d-af7f-4db0-972a-e053d5b3dda8 
  fwd="41.224.13.74" dyno= connect= service= status=503 bytes=


  2016-09-08T07:46:19.868822+00:00 heroku[slug-compiler]: 
  Slug compilation started
  2016-09-08T07:46:19.868831+00:00 heroku[slug-compiler]: 
  Slug compilation finished
  2016-09-08T07:46:19.889451+00:00 heroku[web.1]: 
  State changed from crashed to starting
  2016-09-08T07:46:22.338101+00:00 heroku[web.1]: 
  Starting process with command `npm start`
  2016-09-08T07:46:24.132828+00:00 app[web.1]:
  2016-09-08T07:46:24.132841+00:00 app[web.1]: > PiExpress@0.0.0 start /app
  2016-09-08T07:46:24.132842+00:00 app[web.1]: > node ./bin/www
  2016-09-08T07:46:24.132842+00:00 app[web.1]:
 2016-09-08T07:46:24.845254+00:00 app[web.1]: mongo connected
 2016-09-08T07:46:25.139671+00:00 heroku[web.1]: State changed 
 from starting to up
 2016-09-08T07:46:27.070536+00:00 heroku[router]: at=info 
 method=POST  path="/authenticate/" 
 host=testroomie.herokuapp.com 
 request_id=1a55a638-2e8f-4b22-bc05-3108962d855c      
 fwd="41.224.13.74" dyno=web.1 connect=1ms service=54ms 
 status=200 bytes=1967
2016-09-08T07:46:27.071806+00:00 app[web.1]: 
POST /authenticate/ 200 44.765   ms - 1559
远程:
远程:-->正在压缩。。。
远程:完成:31.2米
远程:-->正在启动。。。
远程:已发布v76
雷米特:https://testroomie.herokuapp.com/ 部署到Heroku
远程:
远程:正在验证部署。。。完成。
警告:您的控制台字体可能不支持Unicode。
如果你在游戏中遇到奇怪的角色
输出,考虑切换到TruteType字体,如控制台!
到https://git.heroku.com/testroomie.git
d12e210..9A6055主机->主机
C:\OSC2016\Herokupul28\u 08\u 16\testroomie>heroku日志
2016-09-08T07:42:42.421017+00:00应用程序[网站1]:在
ServerResponse.header(/app/node\u modules/express
/lib/response.js:718:10)
2016-09-08T07:42:42.421018+00:00应用程序[网站1]:在
ServerResponse.send(/app/node\u modules/express/
lib/response.js:163:12)
2016-09-08T07:42:42.421018+00:00应用程序[网站1]:
在ServerResponse.json(/app/node\u modules/express/
lib/response.js:249:15)
2016-09-08T07:42:42.421019+00:00应用程序[网站1]:
在查询时。(/app/routes/rappels.js:48:21)
2016-09-08T07:42:42.421019+00:00应用程序[网站1]:
在ServerResponse.send(/app/node\u modules/express/
lib/response.js:151:21)
2016-09-08T07:42:42.421020+00:00应用程序[网站1]:
at/app/node_modules/kareem/index.js:177:19
2016-09-08T07:42:42.421021+00:00应用程序[网站1]:
at/app/node_modules/kareem/index.js:109:16
2016-09-08T07:42:42.421021+00:00应用程序[网站1]:
at_合并的tickCallback(内部/流程)/
下一步(勾选js:67:7)
2016-09-08T07:42:42.421022+00:00应用程序[网站1]:
在过程中。\u(内部/过程)/
下一步(勾选js:98:9)
2016-09-08T07:42:42.446749+00:00应用程序[网站1]:
2016-09-08T07:42:42.463235+00:00应用程序[网站1]:npm错误!
Linux 3.13.0-93-通用
2016-09-08T07:42:42.463766+00:00应用程序[网站1]:npm错误!
argv“/app/.heroku/node/bin/node”“/app/.herok
u/node/bin/npm“开始”
2016-09-08T07:42:42.464078+00:00应用程序[网站1]:npm错误!节点v5.11.1
2016-09-08T07:42:42.465018+00:00应用程序[网站1]:npm错误!npm v3.8.6
2016-09-08T07:42:42.465340+00:00应用程序[网站1]:npm错误!代码失效循环
2016-09-08T07:42:42.465579+00:00应用程序[网站1]:npm错误!
PiExpress@0.0.0开始:`node./bin/www`
2016-09-08T07:42:42.465815+00:00应用程序[网站1]:npm错误!退出状态1
2016-09-08T07:42:42.466082+00:00应用程序[网站1]:npm错误!
2016-09-08T07:42:42.466310+00:00应用程序[网站1]:npm错误!失败于
这个PiExpress@0.0.0启动脚本“否”
de./bin/www。
2016-09-08T07:42:42.466535+00:00应用程序[网站1]:npm错误!确保你
有最新版本的
已安装node.js和npm。
2016-09-08T07:42:42.466747+00:00应用程序[网站1]:npm错误!如果你这样做,
这很可能是一个问题
PiExpress软件包,
2016-09-08T07:42:42.466965+00:00应用程序[网站1]:npm错误!与npm本身无关。
2016-09-08T07:42:42.467175+00:00应用程序[网站1]:npm错误!告诉作者
这在您的系统上失败:
2016-09-08T07:42:42.467403+00:00应用程序[网站1]:npm错误!节点。/bin/www
2016-09-08T07:42:42.467614+00:00应用程序[网站1]:npm错误!你可以
获取有关如何通过以下方式打开此项目问题的信息:
2016-09-08T07:42:42.467835+00:00应用程序[网站1]:npm错误!npm bugs Piecxpress
2016-09-08T07:42:42.468054+00:00应用程序[网站1]:npm错误!或者如果
不可用,您可以通过以下方式获取他们的信息:
2016-09-08T07:42:42.468274+00:00应用程序[网站1]:npm错误!npm所有者ls PiExpress
2016-09-08T07:42:42.468492+00:00应用程序[网站1]:npm错误!有
上面可能有额外的日志输出。
2016-09-08T07:42:42.473827+00:00应用程序[网站1]:
2016-09-08T07:42:42.474143+00:00应用程序[网站1]:npm错误!请包括
包含任何支持请求的以下文件:
2016-09-08T07:42:42.474355+00:00应用程序[网站1]:npm错误/app/npm-debug.log
2016-09-08T07:42:42.578312+00:00 heroku[web.1]:进程已退出,状态为1
2016-09-08T07:42:42.613995+00:00 heroku[web.1]:州从
直到崩溃
2016-09-08T07:42:42.615056+00:00 heroku[web.1]:州从
撞车起动
2016-09-08T07:42:45.070840+00:00 heroku[web.1]:启动流程
使用命令“npm start”`
2016-09-08T07:42:47.367719+00:00应用程序[网站1]:
2016-09-08T07:42:47.367733+00:00应用程序[网站1]:>PiExpress@0.0.0启动/应用程序
2016-09-08T07:42:47.367734+00:00应用程序[web.1]:>节点。/bin/www
2016-09-08T07:42:47.367735+00:00应用程序[网站1]:
2016-09-08T07:42:48.034029+00:00应用程序[网站1]:mongo已连接
2016-09-08T07:42:48.641807+00:00 heroku[web.1]:状态已更改
从头到尾
2016-09-08T07:43:41.999170+00:00 heroku[路由器]:at=info
method=POST path=“/authenticate/”host=test
roomie.herokuapp.com
请求id=2c5f72c8-e3ac-4797-88b4-2c84301eac87
fwd=“41.224.13.74”dyno=web.1 connect=1ms service=84ms status=200bytes=1967
2016-09-08T07:43:41.994683+00:00应用程序[网站1]:发布/验证/
200 70.400毫秒-1559毫秒
2016-09-08T07:44:14.756752+00:00 heroku[路由器]:
at=info method=PUT path=“/rappels/57d03a51f67f121100af8cf3”
host=testroomie.herokuapp.com
请求id=c8db23e5-daf1-46d8-a984-f2bba76db5d9
fwd=“41.224.13.74”dyno=web.1连接=0毫秒服务=24毫秒
状态=200字节=608
2016-09-08T07:44:14.772687+00:00应用程序[web.1]:_http_outgoing.js:346
2016-09-08T07:44:14.772723+00:00应用程序[web.1]:抛出新错误
(“发送邮件后无法设置邮件头”。);
2016-09-08T07:44:14.772732+00:00应用程序[网站1]:^
2016-09-08T07:44:14.772740+00:00应用程序[网站1]:
2016-09-08T07:44:14.772749+00:00应用程序[网站1]:
错误:发送邮件后无法设置邮件头。
2016-09-08T07:44:14.772751+00:00应用程序[网站1]:
在ServerResponse.OutgoingMessage.setHeader(_http_outgoing.js:346:11)
2016-09-08T07:44:14.772751+00:00应用程序[网站1]:
在ServerResponse.header(/app/node_modules/expres/lib/response.js:718:10)
2016-09-08T07:44:14.772
res.json(c).send({modif: c.modif});
router.put('/:id', function(req, res, next) {
        models.rappel.findByIdAndUpdate(req.params.id, 
      {$inc: { modif: 1}},  {new: true}, function(err, c){
        if(err) return res.json({error: err});

        return res.json(c).send({modif: c.modif});
       });
      });