Using SIGKILL ( -9 ) instead of the more general SIGTERM (without parameters) or SIGHUP ( -1 ) means that the process has been killed at the OS level. Mongo stores a lot of data in memory in the form of a cache, both for reading and writing. Therefore, using SIGKILL may mean that the data was half written to disk or never will be written at all. In any case, you can get a damaged database or get missing data that was transferred to users or other processes as successfully saved. Classical database systems work around this issue with transaction logs (kernel panic or power failure is essentially the same effect), but Mongo is considered nosql for good reasons, including but not limited to transaction integrity.
This, of course, applies only to the server process, you can kill your node processes in any way that you want from the point of view of mongo. However, in the general case, you should avoid using kill -9 to kill any process for the same reasons that were outlined above. Processes that cannot be cleaned tend to leave a mess. The usual order:
kill <pid>
... Sends SIGTERM , requesting a graceful shutdown, so wait 30 seconds for the process to close if it is still alive:
kill -1 <pid>
... Sends SIGHUP , requesting an immediate shutdown, wait another 30 seconds, at least to complete the process, and finally:
kill -9 <pid>
... If and only if , the process cannot be continued because it causes problems in server stability or resource blocking. In all other cases, just wait.
Regarding the differences between the “graceful” and the “immediate” shutdowns mentioned above, consider having notepad.exe in which you typed 2 lines. An elegant dialog box pops up asking if you want to save it, it immediately turns off without user intervention, and kill immediately stops the process and frees all memory and other resources back to the system. Historically, signals come from old universal mainframes, where SIGHUP is short for "Hangup", indicating that the user has left and cannot return.
Niels keurentjes
source share