How to debug node + mongo connection errors

Problem

I am getting random connections error from my node application to a mongodb server. The node application and the mongodb database are on separate machines. It works most of the time but usually fails when there are a lot of queries.

When that happens I can still run the mongo shell from the mongodb machine. And if I restart the node application, all is well again.

I couldn't seen anything meaningful in the application log, the mongo log and the system log that leads me to some conclusion.

I am suspecting something on the client machine side, but I couldn't find anything that made sense.

Any lead would be appreciated.

Problem courtesy of: machunter

Solution

When using the node-mongodb-native driver you can supply a logger with a doDebug=true flag to Db() and Connection(). It should then output debug information (to Console or whatever depending). This code, for example, appears to output some Connection debug information

Solution courtesy of: Matt Self

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.