For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Socket Settings

In this guide, you can learn about how the Java driver manages socket settings.

You can specify settings for your sockets by using either a connection string or by passing a MongoClientSettings object to the MongoClients constructor. Select the Connection String or MongoClientSettings tab to see the options available:

Option Name
Type
Description

connectTimeoutMS

integer

Specifies the maximum amount of time, in milliseconds, the Java driver waits for a connection to open before timing out. A value of 0 instructs the driver to never time out while waiting for a connection to open.

Default: 10000 (10 seconds)

socketTimeoutMS

integer

Specifies the maximum amount of time, in milliseconds, the Java driver will wait to send or receive a request before timing out. A value of 0 instructs the driver to never time out while waiting to send or receive a request.

Default: 0

This example specifies that the driver will time out after 15 seconds of waiting for a connection to open:

ConnectionString connectionString = "mongodb://<host>:<port>/?connectTimeoutMS=15000"
MongoClient mongoClient = MongoClients.create(connectionString)

For more information about these parameters, see the ConnectionString API documentation.

Rate this page

On this page