1

I want to finish all active requests to mongodb from node when I need to gracefully shutdown the application (control+c / exceptions). I have tried using the .close method, which closes the connection just fine, but does not seem to wait for active requests to complete. The solutions I have seen appear to just keep a counter of live requests. Is there a more elegant solution to this problem?

Franz Payer
  • 4,069
  • 15
  • 53
  • 77
  • Please check out https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/#stop-mongod-processes – sova Sep 05 '16 at 05:45
  • I am trying to shut down my node application, not mongo – Franz Payer Sep 05 '16 at 14:12
  • Ah you want a way to gracefully shut down Node... and make sure all mongo requests get dealt with? Or all requests in general? – sova Sep 07 '16 at 19:30
  • @sova I'm trying to make sure that all mongo requests that I've fired off to mongo get dealt with on mongo before I close the connection and shut down the Node server. – Franz Payer Sep 09 '16 at 17:40
  • In that case I think you can use Promises to ensure that certain tasks are completed before your program is cut/exited/terminated. Perhaps check out this question http://stackoverflow.com/questions/10551499/simplest-way-to-wait-some-asynchronous-tasks-complete-in-javascript – sova Sep 09 '16 at 17:54

0 Answers0