useUnifiedTopology test failed

Hi all,

I’ve got an integration test on my (node.js) app that is checking the correct behaviour in case the connection to the db is not available.

It simply tries to connect to the machine where the db is running, but on a invalid port.

Before adding the useUnifiedTopology (set to true) on the connection options, the test works as expected, I was able to get the MongoNetworkError and drive the app correctly.

With the useUnifiedTopology option, the test failed because I reach the jest timeout.

node --version is v13.8.0
mongodb driver version is 3.5.5

Any hints?

Thanks

Hey @aleb!
The legacy topologies have a “fast fail” mode where connect will return immediately is some network error has occurred (invalid uri, ssl options, etc). The unified topology implements connect as a “server selection” which means it will wait up to serverSelectionTimeoutMS before failing to connect, so the short answer to your question is that you want to reduce that value (either through the connection string, or MongoClient options) to fail faster.

1 Like

Ciao @mbroadst,

thanks for your answer, it works like a charm. I don’t know if this is the right place, but I would document this in the official driver documentation.

For example this option is not mentioned in the MongoClient available options (Class: MongoClient), neither on the reference for the connection settings (Connection Settings).

Thanks for your help.

AB

Glad to hear it @aleb! The documentation is on its way, the unified topology is only opt-in at the moment but will become the default in the upcoming v4 release of the driver. We will include documentation for these connection string options in the 3.6 release of the driver, with a note that they are only supported by the unified topology.

1 Like