NodeJS and MongoDB lose connection

I have 7 NodeJS with Mongoose web services running in a small instance on Amazon AWS and a MongoDB in another small instance.

Everything works with a low level of use (both processor, memory, and network traffic) without high peaks.

But sometimes it seems that these NodeJS services NodeJS losing connection with MongoDB . All methods from services that do not use Mongoose continue to work fine. Those using Mongoose continue the endless call without any answer. I need to restart the services so that they respond again.

This happens randomly, and there is no pattern that I could figure out.

Another strange thing: on average, all services stop together. A rare thing happens to one, but it happens.

I could try splitting all the services into one server each, but that would be very expensive. But first, I would like to know what is happening and fix it.

Can someone help me?

+4
source share
1 answer

Trying to add option '? auto_reconnect = true 'in the connection string may solve your problem.

But according to the documentation, Mongoose by default includes auto_reconnect.

There may be a better chance of understanding what will happen if you publish the logs of your node.js and mongodb servers.

0
source

Source: https://habr.com/ru/post/1482560/


All Articles