Why isn't "connect" option in mongo connection string documented?

Viewed 3227

The issue was that even if i target just one node of my replica set in my connection string, mongo-go-driver always want to discover and connect other nodes.

I found a solution here that basically say i should add the connect option in the connection string.

mongodb://host:27017/authDb?connect=direct

My question is: How good or bad practice is this and why mongo doesn't have documented, are there other available values that this option can have?

2 Answers

How good or bad practice is this and why mongo doesn't have documented, are there other available values that this option can have?

As pointed out in the accepted answer, that this is documented under the driver documentation. Now for the other part of the question.

Generally speaking in the replica set context, you would want to connect to the topology instead of directly to a specific replica set member, with an exception for administrative purposes. Replication is designed to provide redundancy, and connecting directly to one member i.e. Primary is not recommended in case of fail-over.

All of the official MongoDB drivers follows MongoDB Specifications. In regards to the direct connections, the requirement currently is server-discovery-and-monitoring.rst#general-requirements:

Direct connections: A client MUST be able to connect to a single server of any type. This includes querying hidden replica set members, and connecting to uninitialized members (see RSGhost) in order to run "replSetInitiate". Setting a read preference MUST NOT be necessary to connect to a secondary. Of course, the secondary will reject all operations done with the PRIMARY read preference because the slaveOk bit is not set, but the initial connection itself succeeds. Drivers MAY allow direct connections to arbiters (for example, to run administrative commands).

It only specifies that it MUST be able to do so, but not how. MongoDB Go driver is not the only driver that currently supporting the direct option approach, there are also .NET/C# and Ruby as well.

Currently there is an open PR for the specifications to unify the behaviour. In the future, all drivers will have the same way of establishing a direct connection.

Related