Note

The 3.5 release deprecated socket keep-alive settings, also socket keep-alive checks are now on by default.
It is strongly recommended that system keep-alive settings should be configured with shorter timeouts.

MongoClient (since 3.7 release)

A MongoClient instance represents a pool of connections
to the database; you will only need one instance of class MongoClient even with multiple threads.

important

Typically you only create one MongoClient instance for a given MongoDB deployment (e.g. standalone, replica set, or a sharded cluster)
and use it across your application. However, if you do create multiple instances:

MongoClient (legacy API)

A MongoClient instance represents a pool of connections
to the database; you will only need one instance of class MongoClient even with multiple threads.

important

Typically you only create one MongoClient instance for a given MongoDB deployment (e.g. standalone, replica set, or a sharded cluster) and use it across your application. However, if you do create multiple instances: