server-settings

For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!-- Tab options on this page. Append to the .md URL to filter: ?tabs=<id,...> select specific tabs (e.g. ?tabs=nodejs,shell) ?allTabs=true include every tab (no param) default: one tab per tabset

Available tabs: other tabs: uri, MongoClient -->

Server Settings

Overview

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

Configuring Server Settings

Connection String

Include the following parameters in your connection string to modify the driver's behavior when interacting with the server:

Option Name Type Description
appName string Specifies the name of the application provided to MongoDB instances during the connection handshake. Can be used for server logs and profiling. Default: null
serverMonitoringMode string Specifies which server monitoring protocol the driver uses. When set to auto, the monitoring mode is determined by the environment in which the driver is running. The driver uses poll mode in function-as-a-service (FaaS) environments and stream mode in other environments. Default: auto
heartbeatFrequencyMS integer Specifies the frequency, in milliseconds that the driver will wait between attempts to determine the current state of each server in the cluster. Default: 10000 (10 seconds)

This example specifies that the cluster monitor will attempt to reach a server every 15 seconds:

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

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