[DRIVERS-566] Allow replicaSet=1 in MongoDB URLs Created: 04/Sep/18  Updated: 07/Dec/18  Resolved: 01/Oct/18

Status: Closed
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Henrik Ingo (Inactive) Assignee: Bernie Hackett
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident

 Description   

Relevant documentation: https://docs.mongodb.com/manual/reference/connection-string/#replica-set-option

To tell a driver to connect to a list of nodes as a replicaset - such as when I want to use transactions - I need to use replicaSet=myrs option in the MongoDB URL, where "myrs" is the name of the replicaset.

For easily copypasteable examples, it's unfortunate that there is no meaningful default value for the replica set name. For example, I can assume that on most people's laptops, this URL will work:

mongodb://localhost:2017/test

However, this probably won't:

mongodb://localhost:2017/test?replicaSet=replset

I would like to have the option to say "this is a replica set but I don't care about the name". As a strawman suggestion, using 1 for true (and 0 for false) I could:

mongodb://localhost:2017/test?replicaSet=1



 Comments   
Comment by Bernie Hackett [ 01/Oct/18 ]

I don't think we want to do this. The replSet option is in part a way for the application to ensure they are connecting to the correct set. Adding a "any replica set will do" option is better handled by passing two set members in the seed list, which the Java driver will treat as a replica set.

I do think we should make the topology type discovery mechanism consistent between drivers.

Comment by Bernie Hackett [ 05/Sep/18 ]

The SDAM spec has this to say about the initial topology type:

The API for initializing TopologyType is not specified here. Drivers might already have a convention, e.g. a single seed means Single, a setName means ReplicaSetNoPrimary, and a list of seeds means Unknown. There are variations, however: In the Java driver a single seed means Single, but a list containing one seed means Unknown, so it can transition to replica-set monitoring if the seed is discovered to be a replica set member. In contrast, PyMongo requires a non-null setName in order to begin replica-set monitoring, regardless of the number of seeds. This spec does not imply existing driver APIs must change as long as all the required features are somehow supported.

https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring.rst#initial-topologytype

So the behavior is undefined and the behavior you're describing isn't correct for all drivers. Rather than add a special value for replicaSet it probably makes more sense to more strictly define how drivers discover initial topology. For example, having all drivers follow the behavior of the Java driver documented in the spec.

Generated at Thu Feb 08 08:21:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.