Mongos not executing write queries even primary config server available

We have set up a MongoDB DC-DR architecture consisting of 3 shards and 3 config servers in the DC, along with 2 shards, 1 arbiter shard replica, and 2 config replicas in the DR. The priority configuration ensures that whenever the DC goes down, one of the DR servers becomes the primary.

Priorities and Votes:

DC - 3 Shard Replicas

  • host1: (priority: 5, votes: 1)
  • host2: (priority: 4, votes: 1)
  • host3: (priority: 0, votes: 0)

DR - 2 Shard Replicas + Arbiter Shard Replica

  • host1: (priority: 1, votes: 1)
  • host2: (priority: 0.5, votes: 1)
  • host3 (arbiter server): (priority: 0, votes: 1)

DC - 3 Config Server Replicas

  • host1: (priority: 5, votes: 1)
  • host2: (priority: 0, votes: 0)
  • host3: (priority: 0, votes: 0)

DR - 2 Config Server Replicas

  • host1: (priority: 2, votes: 1)
  • host2: (priority: 1, votes: 1)

MongoDB shards are running on port 27019, config servers on 27018, and I am running mongos on DC host1 and host2 to route the queries. Below is the mongos configuration:

mongos --configdb dcreplica1/192.168.84.1:27018,192.168.84.2:27018,192.168.84.3:27018
–logpath mongos.log --keyFile sample.key --fork --logRotate reopen
–logappend --port 27017 --bind_ip_all


**Note:** I haven't included the two config server replicas running in the DR.

### **Issue Faced**  
Whenever all DC servers are turned off, both **config servers and shard replicas in DR** become primary. However, when I run **mongos** in DR using the configuration below, **write queries do not execute through mongos**.  

mongos --configdb dcreplica1/DrHost1_ip:27018,DR_host2_ip:27018 \
--logpath mongos.log --keyFile sample.key --fork --logRotate reopen \
--logappend --port 27017 --bind_ip_all

Interestingly, when I connect directly to a DR shard, write queries execute successfully.

Additional Observation

When the DC comes back online, it automatically becomes primary again, and queries execute properly through the mongos running in DR. However, when DR is primary, queries do not execute, and the control gets stuck indefinitely.

From the mongos logs, I found the following messages:

Ctx:ReplicaSetMonitorTaskExecutor, “msg”:“RSM monitoring host in expedited mode until we detect a primary”, “attr”: {“host”:DC_host1_ip:27018,“replicaset”:“replica_name”}
Ctx:ReplicaSetMonitorTaskExecutor, “msg”:“RSM monitoring host in expedited mode until we detect a primary”, “attr”: {“host”:DC_host2_ip:27018,“replicaset”:“replica_name”}
Ctx:ReplicaSetMonitorTaskExecutor, “msg”:“RSM monitoring host in expedited mode until we detect a primary”, “attr”: {“host”:DC_host3_ip:27018,“replicaset”:“replica_name”}



How can I configure **mongos** to ensure that **write queries execute properly from DR even when DC is offline**? Any suggestions or solutions would be greatly appreciated.  

Thanks in advance!