Replica set failover for write operations
- Last Updated: July 30, 2025
- 2 minute read
- DataDirect Connectors
- ODBC
- MongoDB 8.0
- Documentation
Write operations for replica sets are performed exclusively through connections to the primary member. However, sometimes the primary member can become unavailable, for example, due to hardware failure or traffic overload. If this occurs, the other members elect a secondary member to assume the role of the primary. The ability to promote the secondary member during outages ensures uninterrupted availability of write operations and access to the most current version of data.
When replicate set failover is enabled, the driver handles this behavior by attempting to connect to the primary member for each write operation. If the connection fails, the driver repeats the discovery process until it finds the new primary member or the maximum number of retries have been attempted. You can enable replica set failover for write operations by specifying the name of your replica set using the Replica Set Name (ReplicaSetName) option.
To configure replica set name failover for write operations:
- Set Host Name (HostName) to specify the name or the IP address of the MongoDB server to which you want to connect. For example, mymongodbserver.
- Set Database Name (DatabaseName) to specify the name of the database to which you want to connect. This value is used as the default qualifier for unqualified table names in SQL queries. Required for User/ID password authentication.
- Set Port Number (PortNumber) to specify the port number of the server
listener. The default is
27017. - Set Replica Set Name (ReplicaSetName) to specify the name of the replica set against which you want to execute write operations.
The following examples include the options required for connecting with no authentication, replica set failover for write operations enabled, and replica set failover for read operations set to primary preferred .
Connection string
DRIVER=DataDirect 8.1 MongoDB;AuthenticationMethod=15;DatabaseName=mydb;
HostName=myserver;PortNumber=27017;ReplicaSetName=MyReplicaSet;
odbc.ini
[MongoDB]
Driver=ODBCHOME/lib/ivmongodb81.so
...
Description=DataDirect 8.1 MongoDB
...
AuthenticationMethod=15
...
DatabaseName=mydb
...
HostName=myserver
...
ReplicaSetName=MyReplicaSet
...