MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

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 (https://mongodb.github.io/node-mongodb-native/3.5/api/MongoClient.html), neither on the reference for the connection settings (http://mongodb.github.io/node-mongodb-native/3.5/reference/connecting/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