I have 4 servers each hosting a website and a mongo replica set.
- MongoDB version: v3.4.13
- Driver: PHP
Server 1 is PRIMARY.
- Located on the west coast
Server 2 is SECONDARY with tag: { location: 'east' }
Located on the east coast
I'm connecting to the db with connection string: mongodb://localhost:27017/?replicaSet=rs&readPreference=nearest&readPreferenceTags=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)
- I suspect it's not reading from it's own SECONDARY db because there is about a 3 second lag for any query I run.
How can I tell server 2 to read from it's own local SECONDARY db?
local
? This could either be thelocal
database (where the replication oplog and other non-replicated collections live) or local data (i.e. reading from any other database). I suspect you mean the latter, but it's not clear from the current description. It would also be helpful to edit your description to include information on the driver & version you are connecting with as well as how you are verifying data is being returned from the expected server. – Stennie