-
Type: Question
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.2.6
-
Component/s: Shell
-
Server Development Platform
-
(copied to CRM)
If you have two replica sets with the same name, and you login to replica set 1 then make a new connection to replica set 2 with the Mongo() function, the connection actually goes to replica set 1 when you use it.
For the issue to manifest, you must have two replica sets with the same replica set name, connect to them as replica sets not as individual hosts, and the SSL modes must be the same. We used MongoDB version 4.2.6, but we suspect this issue exists in earlier versions as well.
In the repro below, all members are on the same host, the first replica set is on ports 27017/8/9, and the second is on ports 27027/8/9. A document is added to test.foo to identify the replica set.
Start mongo shell on replica set 2 and show data:
$ mongo "mongodb://admin:REDACT@mongodb-local.computer:27027/test?ssl=true&authSource=admin&replicaSet=m" --sslCAFile tls-certs/public-ca.pem --ssl ... MongoDB Enterprise m:PRIMARY> rs.conf().members[0].host mongodb-local.computer:27027 MongoDB Enterprise m:PRIMARY> db test MongoDB Enterprise m:PRIMARY> db.foo.find() { "_id" : ObjectId("5eac34b18a34c540e6aef514"), "a" : "this is replica set 2" }
Start mongo shell on replica set 1 and show data. Create new connection to replica set 2. When you use the connection to show data, it goes to replica set 1, which is the issue being reported here.
$ mongo "mongodb://admin:REDACT@mongodb-local.computer:27017/test?ssl=true&authSource=admin&replicaSet=m" --sslCAFile tls-certs/public-ca.pem --ssl ... MongoDB Enterprise m:PRIMARY> rs.conf().members[0].host mongodb-local.computer:27017 MongoDB Enterprise m:PRIMARY> db test MongoDB Enterprise m:PRIMARY> db.foo.find() { "_id" : ObjectId("5eac34f76790a129bd1430d3"), "a" : "this is replica set 1" } MongoDB Enterprise m:PRIMARY> shouldbe2 = new Mongo('mongodb://admin:REDACT@mongodb-local.computer:27027/test?replicaSet=m&authSource=admin&ssl=true'); connection to m/mongodb-local.computer:27027 MongoDB Enterprise m:PRIMARY> shouldbe2.getDB('test').foo.find(); { "_id" : ObjectId("5eac34f76790a129bd1430d3"), "a" : "this is replica set 1" } MongoDB Enterprise m:PRIMARY>