Andrew
Andrew

Reputation: 3613

mongodb not using local database in replica set

I have 4 servers each hosting a website and a mongo replica set.

Server 1 is PRIMARY.

Server 2 is SECONDARY with tag: { location: 'east' }

Server 3 and 4 are SECONDARY with no tags.

I want server 2 to read from it's local database, but instead it is reading from primary (or another secondary, I can't tell, but it's definitely not reading from it's local database)

How can I tell server 2 to read from it's own local SECONDARY db?

Upvotes: 0

Views: 776

Answers (2)

Andrew
Andrew

Reputation: 3613

SOLUTION: All servers within the cluster need to be able to connect to all other servers within the cluster.

Turns out, some of my secondary's weren't able to connect to the other secondary's because of some rules placed in my iptables.

Once all servers within the cluster were able to connect to each other the speed increased dramatically.

Upvotes: 0

simagix
simagix

Reputation: 1922

Include readPreferenceTags in your connection string. Refer to the online doc.

By the way, you shouldn't have a even number of nodes in a replica set unless one of them has no voting right.

Upvotes: 0

Related Questions