Too many mongod proccesses

We have test server with 3 different node.js apps running on it. Each application is using the same MongoDB database test instance of which also runs on the same server. So at any given moment of time we have at most 3 different open connections to mongodb server.

The issue is that after each code deployment (which basically is: killing currently running process, code update and starting new process) i see new process(thread of a single proccess) on server which is shown in htop as /usr/bin/mongod --config /etc/mongodb.conf. Thus once in awhile we have to restart the test server because there are too many not used threads like that and it makes the mongod process take all the RAM.

I am not sure why is this happening and looking for solution to fix this issue.

My assumption is that if we simply kill the node.js proccess the connection (and therefore the thread related to this connection) somehow stays alive and therefore instead of killing nodejs process, we should gracefully shut it down with closing the DB connection.

htop is also showing different threads, your mongod isn't started multiple times, which wouldn't be possible with the same config because the port is already in use.

use top or ps aux | grep mongod and you should see just one process.

you can also configure htop not to show those, press F2 > display options > hide userland threads.